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

fix($controller): allow identifiers containing $ #13736

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/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
var $controllerMinErr = minErr('$controller');


var CNTRL_REG = /^(\S+)(\s+as\s+(\w+))?$/;
var CNTRL_REG = /^(\S+)(\s+as\s+([\w$]+))?$/;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps only allow $ at the beginning or is that being too strict?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it crossed my mind, but I thought it was too strict. It complicates things unnecessarily, I think.
(Note that it's already possible to use many more characters using controllerAs.)

function identifierForController(controller, ident) {
if (ident && isString(ident)) return ident;
if (isString(controller)) {
Expand Down
11 changes: 11 additions & 0 deletions test/ng/controllerSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,5 +209,16 @@ describe('$controller', function() {
"Badly formed controller string 'ctrl as'. " +
"Must match `__name__ as __id__` or `__name__`.");
});


it('should allow identifiers containing `$`', function() {
var scope = {};

$controllerProvider.register('FooCtrl', function() { this.mark = 'foo'; });

var foo = $controller('FooCtrl as $foo', {$scope: scope});
expect(scope.$foo).toBe(foo);
expect(scope.$foo.mark).toBe('foo');
});
});
});