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

Incorrect args handling in shellHelper

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: 3.0.16, 4.0.0
    • Component/s: JavaScript, Shell
    • Labels:
    • Server Tooling & Methods
    • ALL

      The shellHelper's code is:

       

      mongos> shellHelper
      function (command, rest, shouldPrint) {
          command = command.trim();
          var args = rest.trim().replace(/\s*;$/, "").split("\s+");
          if (!shellHelper[command])
              throw Error("no command [" + command + "]");
          var res = shellHelper[command].apply(null, args);
          if (shouldPrint) {
              shellPrintHelper(res);
          }
          return res;
      }                                                                                                                                                                                                     
      

      looking at the line which declares the "args", there's a split at the end which by the looks of it, seems to want to split the string by spaces.

       

      The problem is that in this form it doesn't do that, the corect way should pass a "regex object" not a string

       

       

      mongos> "a b".split("\s+")                                                                                                                                                                              [ "a b" ]      // not split by space                                                                                                                                                                                         
      
      mongos> "a\s+b".split("\s+")                                                                                                                                                                            [ "a", "b" ]  // split by the "\s+" string                                                                                                                                                                                           
        
      mongos> "a b".split(/\s+/)                                                                                                                                                                              [ "a", "b" ]  // split by space           
      mongos> "a     b".split(/\s+/)                                                                                                                                                                          [ "a", "b" ]  // split by multiple spaces                                                                                                                                                                                           
                                                                                                                                                                                         
      

       

       

       

            Assignee:
            backlog-server-stm Backlog - Server Tooling and Methods (STM) (Inactive)
            Reporter:
            asharlohmar@gmail.com Lohmar ASHAR
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated: