From 591bac57a083a396224549ebd5e6e1b0c37e0f3d Mon Sep 17 00:00:00 2001 From: Caitlin Potter Date: Fri, 22 Aug 2014 09:26:41 -0400 Subject: [PATCH] fix(ngRepeat): allow aliasAs identifiers which contain but do not match 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 #8719 --- src/ng/directive/ngRepeat.js | 2 +- test/ng/directive/ngRepeatSpec.js | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/ng/directive/ngRepeat.js b/src/ng/directive/ngRepeat.js index 95effc6d33fc..aeb0fb8ecf00 100644 --- a/src/ng/directive/ngRepeat.js +++ b/src/ng/directive/ngRepeat.js @@ -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); } diff --git a/test/ng/directive/ngRepeatSpec.js b/test/ng/directive/ngRepeatSpec.js index d2d81a6af87f..9f7aada2175c 100644 --- a/test/ng/directive/ngRepeatSpec.js +++ b/test/ng/directive/ngRepeatSpec.js @@ -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('
')(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 = [