evennia: [BUG - Develop] funcparser breaks when args contain an odd number of apostrophe or quote marks
Describe the bug
When a string with an odd number of quote or apostrophe characters is put into a funcparser function, it fails to parse the function.
To Reproduce
Steps to reproduce the behavior:
- Put
$crop(spider silk, 5)through the parser and verify it works (output:spide) - Put
$crop(spider's silk, 5)through the parser: one apostrophe, output:$crop(spider's silk, 5) - Then put
$crop(spider's' silk, 5)through the parser: two apostrophies, output:spide - Lastly, put
$crop('spider's' silk, 5)through the parser: three apostrophes, output:$crop('spider's' silk, 5)
Expected behavior
It should successfully parse the function when it’s being given a string that contains a single quote mark or apostrophe.
Develop-branch commit
7f4769bd9
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 20 (20 by maintainers)
Commits related to this issue
- Stop escape ' in funcparser; req double quotes. Resolve #2737. — committed to evennia/evennia by Griatch 2 years ago
- Add tag to catch link-dead puppet. Resolve #2829, #2737 — committed to evennia/evennia by Griatch 2 years ago
- Stop escape ' in funcparser; req double quotes. Resolve #2737. — committed to evennia/evennia by Griatch 2 years ago
- Add tag to catch link-dead puppet. Resolve #2829, #2737 — committed to evennia/evennia by Griatch 2 years ago
Investigating this further, there seems no real way to support single-quoted strings within the funcparser structure while keeping quotes optional for the user (which we want to do, for simplicitly.
While it’s possible to count single quotes to try to guess if the quote is a quote or an apostrophe, this would still make inputs like this impossible:
No matter what you do,
s spiderwill be considered a literal and the'will be lost. It’s even clearer with another example:Here
s, devilands, zombiewill be considered literal strings no matter how clever we design the'-parsing, because there is no way for the system to know the difference between this andIt seems the only way around this is to not treat single quotes in funcparser funcs as literals at all - requiring double quotes.
If I remove special treatment of single quotes, this problem goes away completely. The drawback is that it doesn’t quite match Python syntax anymore (since
'and"wouldn’t nest like Python for example). The last$choicecall above would become a choice between the strings'Tiamat,queen of dragons,'Draculaandlord of the night'. Using double-quotes becomes required.But I think using apostrophes is more likely a thing than requiring to be able to escape with single quotes.
I’m working on it btw, did some refactoring to make the fix easier, should have it working soon.
Yeah, I understand what you mean, and I made the parser like that originally; but discussing and thinking about it now, I think it will be more rare to actually want to have verbatim quotes in the string than it is to want to have commas - and you should be able to ‘escape’ verbatim quotes they way you do it in Python, by alternating
"and', removing another need for a direct use of\.So yes, making the default be to not include the quotes would be a change of the funcparser behavior. The odd-quote case needs to be addressed, as well as properly ‘nesting’ double- and single quotes to escape each other (which I suspect the parser is not properly doing right now). As said, the feature is new to 1.0-dev and behavior is not stable, so changes like this can happen. Considering the intricacies of funcparser, it’s suprising there haven’t been more quirks with it so far 😃
(by the way, I don’t expect you to work on this or anything; I can update the funcparser, it will still be a little while until I circle around to this though)