Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
wid committed Jan 5, 2022
1 parent 56d929a commit c12cbd2
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "101",
"version": "1.6.3",
"version": "1.6.4",
"description": "common javascript utils that can be required selectively that assume es5+",
"main": "index.js",
"scripts": {
Expand Down
3 changes: 3 additions & 0 deletions set.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ var keypather = require('keypather')();
module.exports = set;

function set (obj, key, val) {
if (key === '__proto__' || key === 'prototype' || key === 'constructor') {
throw new Error('Invalid key arguments: __proto__, prototype and constructor cannot be set');
}
var setObj;
if (arguments.length === 1) {
// (setObj)
Expand Down
27 changes: 27 additions & 0 deletions test/test-set.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,33 @@ describe('set', function () {
expect(err).to.exist();
done();
}
});
it('should error when when using __proto__ reserved key', function (done) {
try {
set(() => {}, "__proto__");
}
catch (err) {
expect(err).to.exist();
done();
}
});
it('should error when when using prototype reserved key', function (done) {
try {
set(() => {}, "prototype");
}
catch (err) {
expect(err).to.exist();
done();
}
});
it('should error when when using constructor reserved key', function (done) {
try {
set(() => {}, "constructor");
}
catch (err) {
expect(err).to.exist();
done();
}
});
});
});

0 comments on commit c12cbd2

Please sign in to comment.