New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Singe quote strings - issues with special characters that need escaping #3073
Comments
Thanks for reporting, this will be fixed via ac9052d. I think your second case is not valid: the escape character there is already eaten by JavaScript, so effectively the parser receives a string |
Should be fixed now in |
@josdejong, thank you very much for the quick response and the fix. Yes, this definitely improves the handling of our issues, and you're right about the second test case being wrong. I still have some problems with special characters though. In particular, I can show them using this single line: math.parse(math.parse(`fn('te"st')`).toString()) It results in a syntax error. It happens because: math.parse(`fn('te"st')`).toString() returns So, a single quote string is not preserved when an expression is stringified again. It sounds similar to the issue of whitespace preserving, but I think it can be a bit different category. While ignoring whitespace will never break an expression, updating string delimiters can. Does it seem like something that could be fixed in MathJS without huge effort? |
Ah, that is a good point. We indeed have to escape the |
Right, that's one approach. Another approach would be to maintain the string delimiters while calling .toString(). So, string constants would need to identify what kind of string they are and escape characters according to the original delimiter. That's what I actually meant in my previous message. However, maybe it's not worth the effort if MathJS doesn't preserve other details of the original string, such as whitespace, etc. Having said all that, I managed to fix all the problems on our side, and v11.11.2 made that possible. Thanks for the quick fix! |
It would indeed be neat to remember whether a string was created with single or double quotes. I will leave that out for now though (it is similar to maintaining all whitespaces for example, that would be nice too). I've done a bit of refactoring to not rely on |
The issue with escaping characters in function |
Describe the bug
It seems that single quote strings don't work too well with special characters that need to be escaped, like
"
, or'
.To Reproduce
Open the MathJS website, the webbrowser console, and type:
math.evaluate("'te\"st'")
math.evaluate("'te\'st'")
Result
Exptected result
'te"st'
"te'st"
Other comments
It is worth noting that the first issue (1.) can be workaround by typing
math.evaluate("'te\\\"st'")
. However, the second issue (2.) cannot be fixed by using any number of backslashes.This problem may be related to the following line:
mathjs/src/expression/parse.js
Line 1483 in 4a62e7c
where single-quoted string content is actually enclosed in double quotes. Also, I understand that there are some possible conflicts with the transpose operator, but I am not sure how this could or should affect characters escaping.
The text was updated successfully, but these errors were encountered: