'use strict';
+function isValidKey(key) {
+ return ['__proto__', 'prototype', 'constructor'].indexOf(key) === -1;
+}
+
/**
* @namespace Chart.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];
* @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];
});
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'});