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

shell allows native code to be "saved" to collection and then throws Unexpected identifier when retrieved

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • None
    • 2.4.3
    • Shell
    • None
    • amazon ami linux (~ CentOS 6), and also os x 10.8.3
    • Fully Compatible
    • ALL
    • Hide

      ~> mongo
      MongoDB shell version: 2.4.3
      connecting to: test
      > db.blah.count()  // new empty table
      0
       
      // native and non-native functions 
      > var native = "".trim
      function trim() { [native code] }
      > var nonNative = function() {print('hi')}
      function () {print('hi')}
      > 
      > // everything is cool for the nonNative function
      > db.blah.insert({f:nonNative})
      > db.blah.find()[0]
      {
      	"_id" : ObjectId("517967ac68f5d75f0efedc26"),
      	"f" : function () {print('hi')}
      }
      > 
       
      // lets try and trick it with a native function (it saves fine, bombs on retrieval)
      // note: src/mongo/shell/types.js:L592 thrown below is a "for (var k in obj)" construct.  the native function property bombs this, it is not the source of the error
      > db.blah.insert({f:native})
      > db.blah.find()[1]
      Thu Apr 25 17:28:54.386 JavaScript execution failed: SyntaxError: Unexpected identifier
      Thu Apr 25 17:28:54.386 JavaScript execution failed: Error: 16722 JavaScript execution failed: SyntaxError: Unexpected identifier at src/mongo/shell/types.js:L592 
       
      // record is there, but the property f throws an exception in the shell
      > db.blah.find()[1]._id
      ObjectId("517967c368f5d75f0efedc27")
      > db.blah.find()[1].f
      Thu Apr 25 17:29:29.342 JavaScript execution failed: SyntaxError: Unexpected identifier
      Thu Apr 25 17:29:29.342 JavaScript execution failed: Error: 16722 JavaScript execution failed: SyntaxError: Unexpected identifier
       
      // zero still works
      > db.blah.find()[0]
      {
      	"_id" : ObjectId("517967ac68f5d75f0efedc26"),
      	"f" : function () {print('hi')}
      }
       

      Show
      ~> mongo MongoDB shell version: 2.4.3 connecting to: test > db.blah.count() // new empty table 0   // native and non-native functions > var native = "".trim function trim() { [native code] } > var nonNative = function() {print('hi')} function () {print('hi')} > > // everything is cool for the nonNative function > db.blah.insert({f:nonNative}) > db.blah.find()[0] { "_id" : ObjectId("517967ac68f5d75f0efedc26"), "f" : function () {print('hi')} } >   // lets try and trick it with a native function (it saves fine, bombs on retrieval) // note: src/mongo/shell/types.js:L592 thrown below is a "for (var k in obj)" construct. the native function property bombs this, it is not the source of the error > db.blah.insert({f:native}) > db.blah.find()[1] Thu Apr 25 17:28:54.386 JavaScript execution failed: SyntaxError: Unexpected identifier Thu Apr 25 17:28:54.386 JavaScript execution failed: Error: 16722 JavaScript execution failed: SyntaxError: Unexpected identifier at src/mongo/shell/types.js:L592   // record is there, but the property f throws an exception in the shell > db.blah.find()[1]._id ObjectId("517967c368f5d75f0efedc27") > db.blah.find()[1].f Thu Apr 25 17:29:29.342 JavaScript execution failed: SyntaxError: Unexpected identifier Thu Apr 25 17:29:29.342 JavaScript execution failed: Error: 16722 JavaScript execution failed: SyntaxError: Unexpected identifier   // zero still works > db.blah.find()[0] { "_id" : ObjectId("517967ac68f5d75f0efedc26"), "f" : function () {print('hi')} }  

    Description

      there is a bson "Code" type allowing us to save functions in a collection.

      From the shell, if a native function [like String.prototype.trim used below] is saved to the database, it will throw an Unexpected identifier when retrieved.

      I have not been able to identify the exact source of the error. In the nodejs driver -- and i assume other drivers -- it works fine in the sense that it will not throw an error. Obviously the property still has invalid data.

      Attachments

        Activity

          People

            backlog-server-platform DO NOT USE - Backlog - Platform Team
            hlhicks Henry Hicks
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: