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

Commit 5fe1f39

Browse files
committed
fix($parse): reduce false-positives in isElement tests
There are always going to be false positives here, unfortunately. But testing different properties will hopefully reduce the number of false positives in a meaningful way, without harming performance too much. Closes #4805 Closes #5675
1 parent 2bce71e commit 5fe1f39

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/ng/parse.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ function ensureSafeObject(obj, fullExpression) {
5555
'Referencing the Window in Angular expressions is disallowed! Expression: {0}',
5656
fullExpression);
5757
} else if (// isElement(obj)
58-
obj.children && (obj.nodeName || (obj.on && obj.find))) {
58+
obj.children && (obj.nodeName || (obj.prop && obj.attr && obj.find))) {
5959
throw $parseMinErr('isecdom',
6060
'Referencing DOM nodes in Angular expressions is disallowed! Expression: {0}',
6161
fullExpression);

test/ng/parseSpec.js

+22
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,28 @@ describe('parser', function() {
786786
'$parse', 'isecdom', 'Referencing DOM nodes in Angular expressions is ' +
787787
'disallowed! Expression: a.b.doc.on("click")');
788788
}));
789+
790+
// Issue #4805
791+
it('should NOT throw isecdom when referencing a Backbone Collection', function() {
792+
// Backbone stuff is sort of hard to mock, if you have a better way of doing this,
793+
// please fix this.
794+
var fakeBackboneCollection = {
795+
children: [{}, {}, {}],
796+
find: function() {},
797+
on: function() {},
798+
off: function() {},
799+
bind: function() {}
800+
};
801+
scope.backbone = fakeBackboneCollection;
802+
expect(function() { scope.$eval('backbone'); }).not.toThrow();
803+
});
804+
805+
it('should NOT throw isecdom when referencing an array with node properties', function() {
806+
var array = [1,2,3];
807+
array.on = array.attr = array.prop = array.bind = true;
808+
scope.array = array;
809+
expect(function() { scope.$eval('array'); }).not.toThrow();
810+
});
789811
});
790812
});
791813

0 commit comments

Comments
 (0)