[SERVER-5697] Unmatched quotes in regular expression cause JS shell to enter multi-line mode Created: 24/Apr/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: Minor - P4
Reporter: Barrie Segal Assignee: Tad Marshall
Resolution: Done Votes: 1
Labels: neweng, regex, shell
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to SERVER-13934 Escaping of parentheses/brackets/brac... Closed
is related to SERVER-5809 Double quote escaping bugged Closed
is related to SERVER-3994 Brace matching in mongo shell could b... Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Participants:

 Description   

To reproduce: (in the JS shell)
> db.test.save({_id:1, name:"O'Reilly"})
> db.test.find(

{name:/O'Reilly/}

)
...
Notice that shell enters multi-line mode. Tad says that, "The isBalanced() routine sees the apostrophe/single-quote and scans looking for a matching quote. When it doesn't find one, it goes into multi-line mode. "

A question regarding this was asked on Google Groups: http://groups.google.com/group/mongodb-user/browse_thread/thread/fcd29bf712e49e13



 Comments   
Comment by Tad Marshall [ 18/Mar/13 ]

There was never any reason to enter multi-line mode on an unterminated string, since all you'll get is a syntax error from the JavaScript engine, so the case described here is fixed by the above commit.

There are still potential issues related to not having code that understands regular expressions in the isBalanced() routine, so there will perhaps be other cases related to parentheses, braces, brackets and single and double quotes in regex expressions (e.g. /regex/), but we can leave that to another ticket.

The case described here is fixed.

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

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