Skip to content

Commit

Permalink
Fix matcher cyclic object infinite recursion issue (#245)
Browse files Browse the repository at this point in the history
* Update match-object.js

* Update create-matcher.test.js
  • Loading branch information
spitza authored Sep 12, 2024
1 parent ee12a15 commit 153c0a7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/create-matcher.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,14 @@ describe("matcher", function () {
assert(match.test({ deep: { str: "sinon", ignored: "value" } }));
});

it("returns true for partial matching cyclic object", function () {
var cyclicObj = { a: null };
cyclicObj.a = cyclicObj;
var match = createMatcher({ b: cyclicObj });

assert(match.test({ b: cyclicObj, c: "c" }));
});

it("returns false if a property is not equal", function () {
var match = createMatcher({ str: "sinon", nr: 1 });

Expand Down
4 changes: 4 additions & 0 deletions lib/create-matcher/match-object.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var typeOf = require("@sinonjs/commons").typeOf;

var deepEqualFactory = require("../deep-equal").use;

var identical = require("../identical");
var isMatcher = require("./is-matcher");

var keys = Object.keys;
Expand Down Expand Up @@ -41,6 +42,9 @@ function matchObject(actual, expectation, matcher) {
return false;
}
} else if (typeOf(exp) === "object") {
if (identical(exp, act)) {
return true;
}
if (!matchObject(act, exp, matcher)) {
return false;
}
Expand Down

0 comments on commit 153c0a7

Please sign in to comment.