[SERVER-5809] Double quote escaping bugged Created: 10/May/12 Updated: 11/Jul/16 Resolved: 18/Mar/13 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Shell |
| Affects Version/s: | 2.1.0 |
| Fix Version/s: | 2.5.0 |
| Type: | Bug | Priority: | Trivial - P5 |
| Reporter: | Remon van Vliet | Assignee: | Tad Marshall |
| Resolution: | Done | Votes: | 1 |
| Labels: | neweng | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||||||||||||||
| Backwards Compatibility: | Fully Compatible | ||||||||||||||||||||
| Operating System: | ALL | ||||||||||||||||||||
| Participants: | |||||||||||||||||||||
| Description |
|
This is not allowed : a = {s:"\""}db.test.save( {s:"\""}) This is allowed : a = "\"" ) Shouldn't all of the above work (it does in all other JavaScript contexts I'm aware of). |
| Comments |
| Comment by Catalin Ciurea [ 14/Jan/14 ] | ||||||||
|
It works in 2.4 also by using the unicode code point for double quote:
| ||||||||
| Comment by auto [ 18/Mar/13 ] | ||||||||
|
Author: {u'date': u'2013-03-17T11:22:29Z', u'name': u'Tad Marshall', u'email': u'tad@10gen.com'}Message: When skipping quoted strings in isBalanced(), skip past quotes | ||||||||
| Comment by Gabriel Petrovay [ 23/Oct/12 ] | ||||||||
|
The workaround above is not a general one. It does not work it the text contains more quotes, parenthesis, etc. | ||||||||
| Comment by Tad Marshall [ 10/May/12 ] | ||||||||
|
Right, I was not suggesting this as a workaround ... | ||||||||
| Comment by Remon van Vliet [ 10/May/12 ] | ||||||||
|
Ah, charming | ||||||||
| Comment by Tad Marshall [ 10/May/12 ] | ||||||||
|
It's not that it "is not allowed", the problem is that the "isBalanced()" routine's quote matching doesn't know about escaping quotes, so it thinks that "\"" leaves you inside a quoted string because of the odd number of quote characters. This makes it not recognize the closing brace, thinking it is part of a string. You can make it work by faking it out with a comment ...
The // comment start protects the later part from messing up the JavaScript interpreter, and the " makes isBalanced() think that we're out of the string and then the } can match the earlier opening brace. | ||||||||
| Comment by Remon van Vliet [ 10/May/12 ] | ||||||||
|
By the way, I know it can be done with single quotes, it's more that it seems inconsistent. |