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

Commit

Permalink
fix(ngRepeat): allow aliasAs identifiers which contain but do not mat…
Browse files Browse the repository at this point in the history
…ch reserved words

Currently if a reserved word occurs anywhere within the aliasAs identifier, we throw. This CL fixes
this behaviour by allowing these identifiers, since they are technically perfectly valid.

Closes #8729
  • Loading branch information
caitp committed Aug 22, 2014
1 parent 066c049 commit d713ad1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ng/directive/ngRepeat.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ var ngRepeatDirective = ['$parse', '$animate', function($parse, $animate) {
var keyIdentifier = match[2];

if (aliasAs && (!/^[$a-zA-Z_][$a-zA-Z0-9_]*$/.test(aliasAs) ||
/^null|undefined|this|\$index|\$first|\$middle|\$last|\$even|\$odd|\$parent$/.test(aliasAs))) {
/^(null|undefined|this|\$index|\$first|\$middle|\$last|\$even|\$odd|\$parent)$/.test(aliasAs))) {
throw ngRepeatMinErr('badident', "alias '{0}' is invalid --- must be a valid JS identifier which is not a reserved name.",
aliasAs);
}
Expand Down
30 changes: 30 additions & 0 deletions test/ng/directive/ngRepeatSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,36 @@ describe('ngRepeat', function() {
});


it('should support alias identifiers containing reserved words', inject(function($exceptionHandler) {
scope.x = 'bl';
scope.items = [
{ name : 'red' },
{ name : 'blue' },
{ name : 'green' },
{ name : 'black' },
{ name : 'orange' },
{ name : 'blonde' }
];
forEach([
'null2',
'qthis',
'qthisq',
'fundefined',
'$$parent'
], function(name) {
var expr = 'item in items | filter:x as ' + name + ' track by $index';
element = $compile('<div><div ng-repeat="' + expr + '"></div></div>')(scope);
scope.$digest();
expect(scope[name]).toEqual([
{ name: 'blue' },
{ name: 'black' },
{ name: 'blonde' }
]);
dealoc(element);
});
}));


it('should throw if alias identifier is not a simple identifier', inject(function($exceptionHandler) {
scope.x = 'bl';
scope.items = [
Expand Down

0 comments on commit d713ad1

Please sign in to comment.