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

fix(ngRepeat): allow aliasAs identifiers which contain but do not match reserved words #8729

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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