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

Fields of Object are tab-completed at the top level

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Won't Do
    • Icon: Major - P3 Major - P3
    • None
    • None
    • Shell
    • Server Development Platform
    • ALL
    • Build B (10/30/15), Build C (11/20/15)

    Description

      The fields of Object are erroneously considered as possibilities when tab-completing at the top level. This leads to bizarreties like (multiple lines used to show interactivity):

      MongoDB shell version: 3.1.4
      connecting to: test
      db: test
      > pre
      > pre<TAB>
      > preventExtensions
      2015-06-23T10:01:30.237+1000 E QUERY    [thread1] ReferenceError: preventExtensions is not defined
          at (shell):1:1
      >
      > Object.pre
      > Object.pre<TAB>
      > Object.preventExtensions(
      > Object.preventExtensions(<BACKSPACE>
      > Object.preventExtensions
      function preventExtensions() { [native code] }
      >
      

      The reason is: inside worker in shellAutocomplete of shell/utils.js, when tabbing at the top level, curObj == global. This causes builtinMethods[curObj.__proto__.constructor] to resolve to the fields of Object (from line 424).

      So the fix is just to not do that when tabbing at the top level, e.g.:

      diff --git a/src/mongo/shell/utils.js b/src/mongo/shell/utils.js
      index 9dc2235..1dac232 100644
      --- a/src/mongo/shell/utils.js
      +++ b/src/mongo/shell/utils.js
      @@ -476,7 +476,7 @@ shellAutocomplete = function ( /*prefix*/ ) { // outer scope function called on
                   Object.keySet( curObj ),
                   Object.keySet( curObj.__proto__ ),
                   builtinMethods[curObj] || [], // curObj is a builtin constructor
      -            builtinMethods[curObj.__proto__.constructor] || [], // curObj is made from a builtin constructor
      +            curObj == global ? [] : (builtinMethods[curObj.__proto__.constructor] || []), // curObj is made from a builtin constructor
                   curObj == global ? extraGlobals : [],
                   customComplete( curObj )
               );
      

      Attachments

        Activity

          People

            backlog-server-devplatform [DO NOT ASSIGN] Backlog - Server Development Platform Team (SDP) (Inactive)
            kevin.pulo@mongodb.com Kevin Pulo
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: