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

Commit d01cae2

Browse files
KELiONpkozlowski-opensource
authored andcommitted
fix(ngRepeat) do not allow $id and $root as aliases
Currently user can use `$id` or `$root` as alias in ng-repeat directive that leads to rewriting these scope-related variables. This commit fixes this behavior by throwing an error when user try to use these values. Closes #10778
1 parent d015c8a commit d01cae2

File tree

3 files changed

+5
-1
lines changed

3 files changed

+5
-1
lines changed

docs/content/error/ngRepeat/badident.ngdoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ Reserved names include:
1616
- `this`
1717
- `undefined`
1818
- `$parent`
19+
- `$id`
20+
- `$root`
1921
- `$even`
2022
- `$odd`
2123
- `$first`

src/ng/directive/ngRepeat.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ var ngRepeatDirective = ['$parse', '$animate', function($parse, $animate) {
290290
var keyIdentifier = match[2];
291291

292292
if (aliasAs && (!/^[$a-zA-Z_][$a-zA-Z0-9_]*$/.test(aliasAs) ||
293-
/^(null|undefined|this|\$index|\$first|\$middle|\$last|\$even|\$odd|\$parent)$/.test(aliasAs))) {
293+
/^(null|undefined|this|\$index|\$first|\$middle|\$last|\$even|\$odd|\$parent|\$root|\$id)$/.test(aliasAs))) {
294294
throw ngRepeatMinErr('badident', "alias '{0}' is invalid --- must be a valid JS identifier which is not a reserved name.",
295295
aliasAs);
296296
}

test/ng/directive/ngRepeatSpec.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,8 @@ describe('ngRepeat', function() {
474474
'this',
475475
'undefined',
476476
'$parent',
477+
'$root',
478+
'$id',
477479
'$index',
478480
'$first',
479481
'$middle',

0 commit comments

Comments
 (0)