diff --git a/src/Angular.js b/src/Angular.js index 3de7987ffe7a..9717195e99c0 100644 --- a/src/Angular.js +++ b/src/Angular.js @@ -342,8 +342,10 @@ function baseExtend(dst, objs, deep) { } else if (isElement(src)) { dst[key] = src.clone(); } else { - if (!isObject(dst[key])) dst[key] = isArray(src) ? [] : {}; - baseExtend(dst[key], [src], true); + if (key !== '__proto__') { + if (!isObject(dst[key])) dst[key] = isArray(src) ? [] : {}; + baseExtend(dst[key], [src], true); + } } } else { dst[key] = src; diff --git a/test/AngularSpec.js b/test/AngularSpec.js index 6cf88b0b0e5d..3e270b962968 100644 --- a/test/AngularSpec.js +++ b/test/AngularSpec.js @@ -814,6 +814,19 @@ describe('angular', function() { expect(isElement(dst.jqObject)).toBeTruthy(); expect(dst.jqObject.nodeName).toBeUndefined(); // i.e it is a jqLite/jQuery object }); + + it('should not merge the __proto__ property', function() { + var src = JSON.parse('{ "__proto__": { "xxx": "polluted" } }'); + var dst = {}; + + merge(dst, src); + + if (typeof dst.__proto__ !== 'undefined') { // eslint-disable-line + // Should not overwrite the __proto__ property or pollute the Object prototype + expect(dst.__proto__).toBe(Object.prototype); // eslint-disable-line + } + expect(({}).xxx).toBeUndefined(); + }); });