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

Prototype extensions get saved along with primitive data

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Blocker - P1 Blocker - P1
    • 2.4.0-rc2
    • Affects Version/s: 2.4.0-rc1
    • Component/s: JavaScript
    • Environment:
      OSX
    • ALL
    • Hide

      db.system.js.save({_id: "extendArray", value: function () { Array.prototype.fancyArrayFunction = function()

      { return 'do something'; }

      ; }});
      db.records.insert(

      {foo_id: 1, values:[1,2]}

      )
      var mapFunction1 = function()

      {extendArray(); emit(this.foo_id, this.values); }

      ;
      var reduceFunction1 = function(key, values)

      {return values;}

      ;
      db.records.mapReduce(mapFunction1, reduceFunction1,

      { out: "map_reduce_example" }

      );

      db.map_reduce_example.find({})[0]['value']

      [
      function _cf9f_anonymous_function() {
      return "do something";
      },
      2

      Notice that we have 2 elements in the array as we should, but one of the 2 is the function. If I mongoexport the collection I see all three elements, so the console seems to be having an issue with the length of the array on this also.

      ./mongoexport --jsonArray -d test3 -c map_reduce_example

      connected to: 127.0.0.1
      [{ "_id" : 1, "value" : [ 1, 2, function ()

      {return "do something";}

      ] }]
      exported 1 records

      Show
      db.system.js.save({_id: "extendArray", value: function () { Array.prototype.fancyArrayFunction = function() { return 'do something'; } ; }}); db.records.insert( {foo_id: 1, values:[1,2]} ) var mapFunction1 = function() {extendArray(); emit(this.foo_id, this.values); } ; var reduceFunction1 = function(key, values) {return values;} ; db.records.mapReduce(mapFunction1, reduceFunction1, { out: "map_reduce_example" } ); db.map_reduce_example.find({}) [0] ['value'] [ function _ cf 9 f _anonymous_function() { return "do something"; }, 2 Notice that we have 2 elements in the array as we should, but one of the 2 is the function. If I mongoexport the collection I see all three elements, so the console seems to be having an issue with the length of the array on this also. ./mongoexport --jsonArray -d test3 -c map_reduce_example connected to: 127.0.0.1 [{ "_id" : 1, "value" : [ 1, 2, function () {return "do something";} ] }] exported 1 records

      Running the 3/1 nightly build. Builds before that one do not allow calling functions from system.js

      It appears that functions extending the javascript Array class get added to the array when it gets stored.

            Assignee:
            benjamin.becker Ben Becker
            Reporter:
            aquina Andre Quina
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: