return source;
}
+function isValidKey(key) {
+ return ['__proto__', 'prototype', 'constructor'].indexOf(key) === -1;
+}
+
/**
* The default merger when Chart.helpers.merge is called without merger option.
* Note(SB): also used by mergeConfig and mergeScaleConfig as fallback.
* @private
*/
export function _merger(key, target, source, options) {
+ if (!isValidKey(key)) {
+ return;
+ }
+
const tval = target[key];
const sval = source[key];
* @private
*/
export function _mergerIf(key, target, source) {
+ if (!isValidKey(key)) {
+ return;
+ }
+
const tval = target[key];
const 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'});
});
describe('mergeIf', function() {
+ it('should not allow prototype pollution', function() {
+ var test = helpers.mergeIf({}, 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.mergeIf(target, {a: 2, b: 'foo'});