Skip to content

Commit

Permalink
fix($parse): reduce false-positives in isElement tests
Browse files Browse the repository at this point in the history
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
  • Loading branch information
caitp committed Jan 7, 2014
1 parent affcbad commit 94c97c4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ng/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function ensureSafeObject(obj, fullExpression) {
'Referencing the Window in Angular expressions is disallowed! Expression: {0}',
fullExpression);
} else if (// isElement(obj)
obj.children && (obj.nodeName || (obj.on && obj.find))) {
obj.children && (obj.nodeName || (obj.prop && obj.attr && obj.find))) {
throw $parseMinErr('isecdom',
'Referencing DOM nodes in Angular expressions is disallowed! Expression: {0}',
fullExpression);
Expand Down
22 changes: 22 additions & 0 deletions test/ng/parseSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,28 @@ describe('parser', function() {
'$parse', 'isecdom', 'Referencing DOM nodes in Angular expressions is ' +
'disallowed! Expression: a.b.doc.on("click")');
}));

// Issue #4805
it('should NOT throw isecdom when referencing a Backbone Collection', function() {
// Backbone stuff is sort of hard to mock, if you have a better way of doing this,
// please fix this.
var fakeBackboneCollection = {
children: [{}, {}, {}],
find: function() {},
on: function() {},
off: function() {},
bind: function() {}
};
scope.backbone = fakeBackboneCollection;
expect(function() { scope.$eval('backbone'); }).not.toThrow();
});

it('should NOT throw isecdom when referencing an array with node properties', function() {
var array = [1,2,3];
array.on = array.attr = array.prop = array.bind = true;
scope.array = array;
expect(function() { scope.$eval('array'); }).not.toThrow();
});
});
});

Expand Down

0 comments on commit 94c97c4

Please sign in to comment.