[SERVER-4432] Strange item in mongo shell's autocomplete Created: 05/Dec/11  Updated: 11/Jul/16  Resolved: 13/Dec/11

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

Type: Bug Priority: Trivial - P5
Reporter: Tad Marshall Assignee: Tad Marshall
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Operating System: ALL
Participants:

 Description   

Run the mongo shell, type "cf" and hit tab. You get an auto-completion suggestion of "cf_1_f_x)

{shellAutocomplete(x)}(".

MongoDB shell version: 2.1.0-pre-
connecting to: test
> cf<hit tab here>_1_f_x) {shellAutocomplete(x)}

(

Presumably, some leftover cruft from the shellAutocomplete() code, but I haven't looked into it yet. Tested on Windows and Ubuntu.



 Comments   
Comment by auto [ 13/Dec/11 ]

Author:

{u'login': u'', u'name': u'Tad Marshall', u'email': u'tad@10gen.com'}

Message: SERVER-4432 be more defensive against blank names

Improve code in previous checkin to defend against "function ("
as well as "function(".
Branch: master
https://github.com/mongodb/mongo/commit/95a4c9fbd90efeac9c5e9ed9c3eac74f2611f3c2

Comment by auto [ 13/Dec/11 ]

Author:

{u'login': u'', u'name': u'Tad Marshall', u'email': u'tad@10gen.com'}

Message: SERVER-4432 make "cf_1_f_x)

{shellAutocomplete(x)}

(" go away

Test for no function name specified and use a default name if the
function is unnamed. Start private internal names with leading
underscores. Provide a name for the function anyway. Run the
shellAutocomplete function inside try/catch for safety.
Branch: master
https://github.com/mongodb/mongo/commit/9e0a78c91474bc12e17c28dc6d91a972d89db142

Comment by Tad Marshall [ 13/Dec/11 ]

A couple of things going on here.
1) The code that runs the shellAutocomplete function creates a function in global scope. I don't think it should do this. Global scope should be reserved for the user and for functions that the shell is providing for the user to use. Internal functions not meant to be called by the user should not be created in this scope.
2) The name chosen isn't marked as "private" by starting it with an underscore. We use one or two underscores to (sort of) hide things that don't need to be in the user's face.
3) The code that creates the name assumes that if given a function, then that function will have a name. Not so in this case, and the code that tries to extract the name instead ends up with the body of the function as part of the name.
4) Since the function is going to be visible to the user (because of item 1) it should probably have a reasonable name so it doesn't look suspect.
I'd rather not tackle item 1 because this bug isn't worth it in our final days with SpiderMonkey, but I can do the others.

Comment by Tad Marshall [ 06/Dec/11 ]

Version 1.9.2 does this as well, so it's not new.

19:51:29.88 C:\Bin\Mongo192x64> .\mongo --nodb
MongoDB shell version: 1.9.2
> cf<tab>_1_f_x)

{shellAutocomplete(x)}

(
Mon Dec 05 19:53:03 SyntaxError: missing ; before statement (shell):1
>

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