Skip to content

Commit

Permalink
fix: bug with [__proto__]
Browse files Browse the repository at this point in the history
  • Loading branch information
b-heilman committed Jan 25, 2022
1 parent 4bdc994 commit 29b0162
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bmoor",
"version": "0.10.0",
"version": "0.10.1",
"author": "Brian Heilman <das.ist.junk@gmail.com>",
"description": "A basic foundation for other libraries, establishing useful patterbs, and letting them be more.",
"license": "MIT",
Expand Down Expand Up @@ -29,7 +29,8 @@
},
"scripts": {
"lint": "node ./node_modules/eslint/bin/eslint ./src",
"test": "npm run prettier && mocha --recursive \"./src/**/*.spec.js\"",
"prettier": "npx prettier --write ./src && npm run lint"
"test": "mocha --recursive \"./src/**/*.spec.js\"",
"prettier": "npx prettier --write ./src",
"finalize": "npm run lint && npm run prettier && npm run test"
}
}
8 changes: 6 additions & 2 deletions src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ function set(root, space, value) {
val = space.pop();

for (i = 0, c = space.length; i < c; i++) {
nextSpace = space[i];
nextSpace = String(space[i]);

if (
nextSpace === '__proto__' ||
Expand All @@ -205,6 +205,8 @@ function set(root, space, value) {
}

function _makeSetter(property, next) {
property = String(property);

if (
property === '__proto__' ||
property === 'constructor' ||
Expand Down Expand Up @@ -265,7 +267,7 @@ function get(root, path) {
space = parse(path);
if (space.length) {
for (i = 0, c = space.length; i < c; i++) {
nextSpace = space[i];
nextSpace = String(space[i]);

if (
nextSpace === '__proto__' ||
Expand All @@ -287,6 +289,8 @@ function get(root, path) {
}

function _makeGetter(property, next) {
property = String(property);

if (
property === '__proto__' ||
property === 'constructor' ||
Expand Down
8 changes: 8 additions & 0 deletions src/core.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ describe('Testing object setting/getting', function () {

expect(t.polluted).to.not.equal(true);
});

it('should not allow __proto__ when in array', function () {
var t = {};

bmoor.set(t, [['__proto__'], 'polluted'], 'polluted');

expect(t.polluted).to.not.equal('polluted');
});
});

describe('::makeSetter', function () {
Expand Down

0 comments on commit 29b0162

Please sign in to comment.