Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit b8e8f9a

Browse files
fix(Angular): properly compare RegExp with other objects for equality
Fixes #11204 Closes #11205
1 parent 01161a0 commit b8e8f9a

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/Angular.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -850,10 +850,11 @@ function equals(o1, o2) {
850850
} else if (isDate(o1)) {
851851
if (!isDate(o2)) return false;
852852
return equals(o1.getTime(), o2.getTime());
853-
} else if (isRegExp(o1) && isRegExp(o2)) {
854-
return o1.toString() == o2.toString();
853+
} else if (isRegExp(o1)) {
854+
return isRegExp(o2) ? o1.toString() == o2.toString() : false;
855855
} else {
856-
if (isScope(o1) || isScope(o2) || isWindow(o1) || isWindow(o2) || isArray(o2)) return false;
856+
if (isScope(o1) || isScope(o2) || isWindow(o1) || isWindow(o2) ||
857+
isArray(o2) || isDate(o2) || isRegExp(o2)) return false;
857858
keySet = {};
858859
for (key in o1) {
859860
if (key.charAt(0) === '$' || isFunction(o1[key])) continue;

test/AngularSpec.js

+11
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,7 @@ describe('angular', function() {
367367
expect(equals(new Date(undefined), new Date(0))).toBe(false);
368368
expect(equals(new Date(undefined), new Date(null))).toBe(false);
369369
expect(equals(new Date(undefined), new Date('wrong'))).toBe(true);
370+
expect(equals(new Date(), /abc/)).toBe(false);
370371
});
371372

372373
it('should correctly test for keys that are present on Object.prototype', function() {
@@ -384,12 +385,22 @@ describe('angular', function() {
384385
expect(equals(/abc/, /def/)).toBe(false);
385386
expect(equals(/^abc/, /abc/)).toBe(false);
386387
expect(equals(/^abc/, '/^abc/')).toBe(false);
388+
expect(equals(/abc/, new Date())).toBe(false);
387389
});
388390

389391
it('should return false when comparing an object and an array', function() {
390392
expect(equals({}, [])).toBe(false);
391393
expect(equals([], {})).toBe(false);
392394
});
395+
396+
it('should return false when comparing an object and a RegExp', function() {
397+
expect(equals({}, /abc/)).toBe(false);
398+
expect(equals({}, new RegExp('abc', 'i'))).toBe(false);
399+
});
400+
401+
it('should return false when comparing an object and a Date', function() {
402+
expect(equals({}, new Date())).toBe(false);
403+
});
393404
});
394405

395406

0 commit comments

Comments
 (0)