Skip to content

Commit

Permalink
fix an edge case with non-enumerable properties
Browse files Browse the repository at this point in the history
  • Loading branch information
fasttime committed Dec 29, 2023
1 parent b6732ba commit fac37ba
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/config/flat-config-schema.js
Expand Up @@ -114,7 +114,7 @@ function deepMerge(first, second, mergeMap = new Map()) {
for (const key of Object.keys(second)) {

// avoid hairy edge case
if (key === "__proto__") {
if (key === "__proto__" || !Object.prototype.propertyIsEnumerable.call(first, key)) {
continue;
}

Expand Down
30 changes: 30 additions & 0 deletions tests/lib/config/flat-config-schema.js
Expand Up @@ -199,6 +199,36 @@ describe("merge", () => {
assert.deepStrictEqual(result, { foo: void 0, bar: void 0, baz: void 0 });
});

it("considers only own enumerable properties", () => {
const first = {
__proto__: { inherited1: "A" }, // non-own properties are not considered
included1: "B",
notMerged1: { first: true }
};
const second = {
__proto__: { inherited2: "C" }, // non-own properties are not considered
included2: "D",
notMerged2: { second: true }
};

// non-enumerable properties are not considered
Object.defineProperty(first, "notMerged2", { enumerable: false, value: { first: true } });
Object.defineProperty(second, "notMerged1", { enumerable: false, value: { second: true } });

const result = merge(first, second);

assert.deepStrictEqual(
result,
{
included1: "B",
included2: "D",
notMerged1: { first: true },
notMerged2: { second: true }
}
);
confirmLegacyMergeResult(first, second, result);
});

it("merges objects with self-references", () => {
const first = { foo: 42 };

Expand Down

0 comments on commit fac37ba

Please sign in to comment.