From f5733246a43ef4e7b649d54e820aafa4ef85bcda Mon Sep 17 00:00:00 2001 From: GramParallelo Date: Wed, 23 Mar 2022 16:31:47 -0700 Subject: [PATCH] Revert "When objects are merged together, the target prototype can be polluted. (#7918)" This reverts commit dff7140070c4e68731f17d577cca9fd82fe55498. --- src/helpers/helpers.core.js | 16 ---------------- test/specs/helpers.core.tests.js | 5 ----- 2 files changed, 21 deletions(-) diff --git a/src/helpers/helpers.core.js b/src/helpers/helpers.core.js index bd26c2a0836..350a2075091 100644 --- a/src/helpers/helpers.core.js +++ b/src/helpers/helpers.core.js @@ -1,9 +1,5 @@ 'use strict'; -function isValidKey(key) { - return ['__proto__', 'prototype', 'constructor'].indexOf(key) === -1; -} - /** * @namespace Chart.helpers */ @@ -200,12 +196,6 @@ var helpers = { * @private */ _merger: function(key, target, source, options) { - if (!isValidKey(key)) { - // We want to ensure we do not copy prototypes over - // as this can pollute global namespaces - return; - } - var tval = target[key]; var sval = source[key]; @@ -221,12 +211,6 @@ var helpers = { * @private */ _mergerIf: function(key, target, source) { - if (!isValidKey(key)) { - // We want to ensure we do not copy prototypes over - // as this can pollute global namespaces - return; - } - var tval = target[key]; var sval = source[key]; diff --git a/test/specs/helpers.core.tests.js b/test/specs/helpers.core.tests.js index 28e15989dd1..cdda01b9674 100644 --- a/test/specs/helpers.core.tests.js +++ b/test/specs/helpers.core.tests.js @@ -304,11 +304,6 @@ describe('Chart.helpers.core', function() { }); describe('merge', function() { - it('should not allow prototype pollution', function() { - var test = helpers.merge({}, JSON.parse('{"__proto__":{"polluted": true}}')); - expect(test.prototype).toBeUndefined(); - expect(Object.prototype.polluted).toBeUndefined(); - }); it('should update target and return it', function() { var target = {a: 1}; var result = helpers.merge(target, {a: 2, b: 'foo'});