Skip to content

Commit 1eac46b

Browse files
committed
[Fix] check extra properties on regexps
See #40 (comment)
1 parent e4febb4 commit 1eac46b

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,8 @@ function objEquiv(a, b, opts, channel) {
290290
var aIsRegex = isRegex(a);
291291
var bIsRegex = isRegex(b);
292292
if (aIsRegex !== bIsRegex) { return false; }
293-
if (aIsRegex || bIsRegex) {
294-
return a.source === b.source && flags(a) === flags(b);
293+
if ((aIsRegex || bIsRegex) && (a.source !== b.source || flags(a) !== flags(b))) {
294+
return false;
295295
}
296296

297297
var aIsDate = isDate(a);

test/cmp.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,17 @@ test('Dates', function (t) {
261261
st.end();
262262
});
263263

264+
var a = new Date('2000');
265+
var b = new Date('2000');
266+
b.foo = true;
267+
t.deepEqualTest(
268+
a,
269+
b,
270+
'two identical Dates, one with an extra property',
271+
false,
272+
false
273+
);
274+
264275
t.end();
265276
});
266277

@@ -294,6 +305,22 @@ test('buffers', { skip: typeof Buffer !== 'function' }, function (t) {
294305
t.end();
295306
});
296307

308+
test('Arrays', function (t) {
309+
var a = [];
310+
var b = [];
311+
b.foo = true;
312+
313+
t.deepEqualTest(
314+
a,
315+
b,
316+
'two identical arrays, one with an extra property',
317+
false,
318+
false
319+
);
320+
321+
t.end();
322+
});
323+
297324
test('booleans and arrays', function (t) {
298325
t.deepEqualTest(
299326
true,
@@ -525,6 +552,17 @@ test('regexen', function (t) {
525552
st.end();
526553
});
527554

555+
var a = /abc/gi;
556+
var b = /abc/gi;
557+
b.foo = true;
558+
t.deepEqualTest(
559+
a,
560+
b,
561+
'two identical regexes, one with an extra property',
562+
false,
563+
false
564+
);
565+
528566
t.end();
529567
});
530568

0 commit comments

Comments
 (0)