[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:
Duplicate
is duplicated by SERVER-8554 Mongo shell has trouble parsing \" Closed
Related
related to SERVER-5697 Unmatched quotes in regular expressio... Closed
is related to SERVER-3994 Brace matching in mongo shell could b... Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Participants:

 Description   

This is not allowed :

a =

{s:"\""}

db.test.save(

{s:"\""}

)

This is allowed :

a = "\""
db.test.save(

{s: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:

(mongod-2.4.3) test> db.test.save({s : "\u0022"})
Inserted 1 record(s) in 188ms
(mongod-2.4.3) test> db.test.find()
{
  "_id": ObjectId("52d502906b1252b43283b84a"),
  "s": "\""
}
(mongod-2.4.3) test>              

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: SERVER-5809 SERVER-5697 Improve quote handling in the shell

When skipping quoted strings in isBalanced(), skip past quotes
escaped with backslash. Do not enter multi-line mode when a
line ends with an unterminated string. Add startup test cases
for issues raised by these tickets.
Branch: master
https://github.com/mongodb/mongo/commit/ec3aba682ce0e2f8312526895c7fda9719c7caa5

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 ... . We need to make the command line scanning smarter.

Comment by Remon van Vliet [ 10/May/12 ]

Ah, charming Will wait for fix.

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 ...

> a={s:"\""}//"}
{ "s" : "\"" }

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.

Generated at Thu Feb 08 03:09:56 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.