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

Incorrect args handling in shellHelper

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Needs Scheduling
    • Priority: Minor - P4
    • Resolution: Unresolved
    • Affects Version/s: 3.0.16, 4.0.0
    • Fix Version/s: None
    • Component/s: JavaScript, Shell
    • Labels:
      None
    • Operating System:
      ALL

      Description

      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                                                                                                                                                                                           
                                                                                                                                                                                         
      

       

       

       

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated: