[SERVER-41832] Incorrect args handling in shellHelper Created: 20/Jun/19  Updated: 06/Dec/22

Status: Backlog
Project: Core Server
Component/s: JavaScript, Shell
Affects Version/s: 3.0.16, 4.0.0
Fix Version/s: None

Type: Bug Priority: Minor - P4
Reporter: Lohmar ASHAR Assignee: Backlog - Server Tooling and Methods (STM) (Inactive)
Resolution: Unresolved Votes: 0
Labels: move-stm
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
Assigned Teams:
Server Tooling & Methods
Operating System: ALL
Participants:

 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                                                                                                                                                                                           
                                                                                                                                                                                   

 

 

 



 Comments   
Comment by Steven Vannelli [ 10/May/22 ]

Moving this ticket to the Backlog and removing the "Backlog" fixVersion as per our latest policy for using fixVersions.

Comment by Danny Hatcher (Inactive) [ 21/Jun/19 ]

Thanks for your report. I have forwarded this ticket to the appropriate team to take a look.

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