diff --git a/index.js b/index.js index 3f6e3bc..5f06a17 100644 --- a/index.js +++ b/index.js @@ -290,8 +290,8 @@ function objEquiv(a, b, opts, channel) { var aIsRegex = isRegex(a); var bIsRegex = isRegex(b); if (aIsRegex !== bIsRegex) { return false; } - if (aIsRegex || bIsRegex) { - return a.source === b.source && flags(a) === flags(b); + if ((aIsRegex || bIsRegex) && (a.source !== b.source || flags(a) !== flags(b))) { + return false; } var aIsDate = isDate(a); diff --git a/test/cmp.js b/test/cmp.js index e3dca68..087fd4d 100644 --- a/test/cmp.js +++ b/test/cmp.js @@ -261,6 +261,17 @@ test('Dates', function (t) { st.end(); }); + var a = new Date('2000'); + var b = new Date('2000'); + b.foo = true; + t.deepEqualTest( + a, + b, + 'two identical Dates, one with an extra property', + false, + false + ); + t.end(); }); @@ -294,6 +305,22 @@ test('buffers', { skip: typeof Buffer !== 'function' }, function (t) { t.end(); }); +test('Arrays', function (t) { + var a = []; + var b = []; + b.foo = true; + + t.deepEqualTest( + a, + b, + 'two identical arrays, one with an extra property', + false, + false + ); + + t.end(); +}); + test('booleans and arrays', function (t) { t.deepEqualTest( true, @@ -525,6 +552,17 @@ test('regexen', function (t) { st.end(); }); + var a = /abc/gi; + var b = /abc/gi; + b.foo = true; + t.deepEqualTest( + a, + b, + 'two identical regexes, one with an extra property', + false, + false + ); + t.end(); });