Skip to content

Commit

Permalink
Merge pull request #231 from hapijs/backport-proto-fix
Browse files Browse the repository at this point in the history
Backport proto fix
  • Loading branch information
nlf committed Feb 15, 2018
2 parents 1db691b + 0cd2a12 commit 623667e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ exports.merge = function (target, source, isNullOverride /* = true */, isMergeAr
const keys = Object.keys(source);
for (let i = 0; i < keys.length; ++i) {
const key = keys[i];
if (key === '__proto__') {
continue;
}

const value = source[key];
if (value &&
typeof value === 'object') {
Expand Down
10 changes: 10 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,16 @@ describe('merge()', () => {
expect(a.x.toString()).to.equal('abc');
done();
});

it('skips __proto__', (done) => {

const a = '{ "ok": "value", "__proto__": { "test": "value" } }';

const b = Hoek.merge({}, JSON.parse(a));
expect(b).to.equal({ ok: 'value' });
expect(b.test).to.equal(undefined);
done();
});
});

describe('applyToDefaults()', () => {
Expand Down

0 comments on commit 623667e

Please sign in to comment.