Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/compat/predicate/isMatch.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
expect(isMatch(null, { a: 1 })).toBe(false);

Check failure on line 20 in src/compat/predicate/isMatch.spec.ts

View workflow job for this annotation

GitHub Actions / codecov

src/compat/predicate/isMatch.spec.ts > isMatch > should handle null correctly

AssertionError: expected true to be false // Object.is equality - Expected + Received - false + true ❯ src/compat/predicate/isMatch.spec.ts:20:37
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
expect(isMatch(null, null)).toBe(true);
Expand Down Expand Up @@ -316,6 +316,24 @@
delete numberProto.b;
});

it('should return `false` when target is primitive and source is object with undefined values (Issue #1399)', () => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
expect(isMatch('bar', { anyKey: undefined })).toBe(false);
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
expect(isMatch(123, { anyKey: undefined })).toBe(false);
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
expect(isMatch(true, { anyKey: undefined })).toBe(false);
});

it('should return `false` when target is primitive and source is empty object nested (Issue #1399)', () => {
expect(isMatch({ value: 'bar' }, { value: {} })).toBe(false);
expect(isMatch({ value: 123 }, { value: {} })).toBe(false);
expect(isMatch({ value: true }, { value: {} })).toBe(false);
});

it(`should return \`false\` when \`object\` is nullish`, () => {
// eslint-disable-next-line no-sparse-arrays
const values = [, null, undefined];
Expand All @@ -331,7 +349,7 @@
}
});

expect(actual).toEqual(expected);

Check failure on line 352 in src/compat/predicate/isMatch.spec.ts

View workflow job for this annotation

GitHub Actions / codecov

src/compat/predicate/isMatch.spec.ts > isMatch > should return `false` when `object` is nullish

AssertionError: expected [ undefined, true, true ] to deeply equal [ undefined, false, false ] - Expected + Received Array [ undefined, - false, - false, + true, + true, ] ❯ src/compat/predicate/isMatch.spec.ts:352:20
});

it(`should return \`true\` when comparing an empty \`source\``, () => {
Expand Down
9 changes: 8 additions & 1 deletion src/compat/predicate/isMatchWith.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,14 @@ function isObjectMatch(
const keys = Object.keys(source as any);

if (target == null) {
return keys.length === 0;
if (stack && stack.size > 0 && !isObject(target)) {
return false;
}
return true;
}

if (!isObject(target)) {
return false;
}

if (keys.length === 0) {
Expand Down
Loading