[SERVER-3994] Brace matching in mongo shell could be better Created: 01/Oct/11  Updated: 24/Mar/20  Resolved: 24/Mar/20

Status: Closed
Project: Core Server
Component/s: Shell
Affects Version/s: 2.0.0
Fix Version/s: None

Type: Improvement Priority: Trivial - P5
Reporter: Tad Marshall Assignee: DO NOT USE - Backlog - Platform Team
Resolution: Won't Fix Votes: 0
Labels: platforms-re-triaged
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Any


Issue Links:
Related
related to SERVER-14430 Shell in interactive mode does not wa... Backlog
related to SERVER-5697 Unmatched quotes in regular expressio... Closed
related to SERVER-5809 Double quote escaping bugged Closed
is related to SERVER-6693 Copy-pasting multi-line strings with ... Closed
is related to SERVER-13934 Escaping of parentheses/brackets/brac... Closed
Participants:

 Description   

From code inspection of the isBalanced() function in shell/dbshell.cpp, the function is a little too eager to consider an expression balanced. It will return true if it ever finds more closing parentheses or braces than opening ones even if it has open ones of the other type. This doesn't matter much because any JavaScript with more closing elements that opening ones will generate a syntax error anyway and with command line recall and editing it is easy to fix. But perhaps the testing could be smartened up a little to be more helpful.

Example 1)

a=function({)

This puts the shell into multi-line mode even though the code has enough information to know that the line we just entered is wrong.

Example 2)

a=function(})

This does not go into multi-line mode because we have more closing braces than opening ones.

Example 3)

a=function(){existingVar.func(7)); veryLongExpression =

Even though the opening brace is unclosed, the extra right parenthesis causes the code to consider the expression balanced.

This is probably a very low priority bug and may not be worth the time to fix.


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