Skip to content

Commit

Permalink
back port patch for 4.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
doowb committed Aug 16, 2022
1 parent 8353e4d commit 09c4b10
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ function createKey(pattern, options) {
}

function isValidKey(key) {
if (typeof key !== 'string' && typeof key !== 'number') {
key = String(key);
}

return key !== '__proto__' && key !== 'constructor' && key !== 'prototype';
}

Expand Down
9 changes: 9 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,3 +210,12 @@ describe('options', function() {
assert.equal(o.a['{b.c.d}'].e, 'c');
});
});

describe('patches', function() {
it('should not allow setting an unsafe key', function() {
const o = {};
assert.equal({}.foo, undefined);
set(o, [['__proto__'], 'foo'], 'bar');
assert.equal({}.foo, undefined);
});
});

0 comments on commit 09c4b10

Please sign in to comment.