Skip to content

Commit 153c0a7

Browse files
authored
Fix matcher cyclic object infinite recursion issue (#245)
* Update match-object.js * Update create-matcher.test.js
1 parent ee12a15 commit 153c0a7

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

lib/create-matcher.test.js

+8
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,14 @@ describe("matcher", function () {
129129
assert(match.test({ deep: { str: "sinon", ignored: "value" } }));
130130
});
131131

132+
it("returns true for partial matching cyclic object", function () {
133+
var cyclicObj = { a: null };
134+
cyclicObj.a = cyclicObj;
135+
var match = createMatcher({ b: cyclicObj });
136+
137+
assert(match.test({ b: cyclicObj, c: "c" }));
138+
});
139+
132140
it("returns false if a property is not equal", function () {
133141
var match = createMatcher({ str: "sinon", nr: 1 });
134142

lib/create-matcher/match-object.js

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ var typeOf = require("@sinonjs/commons").typeOf;
66

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

9+
var identical = require("../identical");
910
var isMatcher = require("./is-matcher");
1011

1112
var keys = Object.keys;
@@ -41,6 +42,9 @@ function matchObject(actual, expectation, matcher) {
4142
return false;
4243
}
4344
} else if (typeOf(exp) === "object") {
45+
if (identical(exp, act)) {
46+
return true;
47+
}
4448
if (!matchObject(act, exp, matcher)) {
4549
return false;
4650
}

0 commit comments

Comments
 (0)