[BUG - Develop] funcparser breaks when args contain an odd number of apostrophe or quote marks
See original GitHub issueDescribe 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
Issue Analytics
- State:
- Created a year ago
- Comments:20 (20 by maintainers)
Top Results From Across the Web
Bug with quotes in quotes and scripts (#1742) · Issues - GitLab
Hi, I have the following in my gitlab-ci.yml (I removed what I think ... and that breaks the use of quotes inside the...
Read more >PowerShell stripping double quotes from command line ...
Powershell will auto-quote (enclose in < " >) a single argument string, if it contains spaces and the spaces don't mix with an...
Read more >ASCII and Unicode quotation marks
In ASCII it is used to represent a punctuation mark (such as right single quotation mark, left single quotation mark, apostrophe punctuation, vertical...
Read more >Apostrophes and double quotes don't show up until I type the ...
This happens with double quotes " , apostrophes ' and tilde ~ characters. What could possibly be causing this? This occurs in all...
Read more >SQuirreL SQL Client / Bugs / #1480 Oracle alternate quoting ...
But if the literal string has an odd number of single quotation marks inside the literal string, e.g.. select q'{test' }' from dual;....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub 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:
No matter what you do,
s spider
will be considered a literal and the'
will be lost. It’s even clearer with another example:Here
s, devil
ands, 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 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$choice
call above would become a choice between the strings'Tiamat
,queen of dragons
,'Dracula
andlord 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.