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

Prototype extensions get saved along with primitive data

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Blocker - P1 Blocker - P1
    • 2.4.0-rc2
    • 2.4.0-rc1
    • JavaScript
    • 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

    Description

      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.

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved: