Skip to content

Commit 56f4849

Browse files
committedNov 24, 2018
Support enumerable symbol properties in merge()
1 parent 96ab1bc commit 56f4849

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed
 

‎lib/index.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,12 @@ exports.merge = function (target, source, isNullOverride /* = true */, isMergeAr
126126
return target;
127127
}
128128

129-
const keys = Object.keys(source);
129+
const keys = Reflect.ownKeys(source);
130130
for (let i = 0; i < keys.length; ++i) {
131131
const key = keys[i];
132-
if (key === '__proto__') {
132+
if (key === '__proto__' ||
133+
!Object.prototype.propertyIsEnumerable.call(source, key)) {
134+
133135
continue;
134136
}
135137

‎test/index.js

+9
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,15 @@ describe('merge()', () => {
617617
expect(a.x).to.equal(/test/);
618618
});
619619

620+
it('overrides Symbol properties', () => {
621+
622+
const sym = Symbol();
623+
const a = { [sym]: 1 };
624+
625+
Hoek.merge({ [sym]: {} }, a);
626+
expect(a[sym]).to.equal(1);
627+
});
628+
620629
it('skips __proto__', () => {
621630

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

0 commit comments

Comments
 (0)
Please sign in to comment.