Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-3994

Brace matching in mongo shell could be better

    • Type: Icon: Improvement Improvement
    • Resolution: Won't Fix
    • Priority: Icon: Trivial - P5 Trivial - P5
    • None
    • Affects Version/s: 2.0.0
    • Component/s: Shell
    • Environment:
      Any

      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.

            Assignee:
            backlog-server-platform DO NOT USE - Backlog - Platform Team
            Reporter:
            tad Tad Marshall
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: