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:

  1. Put $crop(spider silk, 5) through the parser and verify it works (output: spide)
  2. Put $crop(spider's silk, 5) through the parser: one apostrophe, output: $crop(spider's silk, 5)
  3. Then put $crop(spider's' silk, 5) through the parser: two apostrophies, output: spide
  4. 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

Most upvoted comments

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:

"$crop(The wizard's spider's wicked web, 5)" 

No matter what you do, s spider will be considered a literal and the ' will be lost. It’s even clearer with another example:

"This is the $choice(spider's, devil's, mummy's, zombie's) curse!"

Here s, devil and s, zombie will 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 and

"This is $choice('Tiamat, queen of dragons', 'Dracula, lord of the night') we are talking about.")

It 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 $choice call above would become a choice between the strings 'Tiamat, queen of dragons, 'Dracula and lord 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)