Skip to content

Commit 4efd11a

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 angular#4805
1 parent affcbad commit 4efd11a

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

0 commit comments

Comments
 (0)