Skip to content

Commit

Permalink
[Fix] check extra properties on regexps
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Dec 4, 2019
1 parent e4febb4 commit 1eac46b
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
38 changes: 38 additions & 0 deletions test/cmp.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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();
});

Expand Down

0 comments on commit 1eac46b

Please sign in to comment.