fix($compile): sanitize special chars in directive name

This fixes regression bug
when directive name with preceeding special char
in HTML markup does not match the registered name.
(introduced in https://github.com/angular/angular.js/commit/73050cdda04675bfa6705dc841ddbbb6919eb048)

Closes #16314
Closes #16278
This commit is contained in:
Denys B
2017-11-17 12:55:18 +02:00
committed by Martin Staffa
parent 873e26347f
commit 12cf994fcc
2 changed files with 24 additions and 1 deletions
+3 -1
View File
@@ -3647,7 +3647,9 @@ var SPECIAL_CHARS_REGEXP = /[:\-_]+(.)/g;
function directiveNormalize(name) {
return name
.replace(PREFIX_REGEXP, '')
.replace(SPECIAL_CHARS_REGEXP, fnCamelCaseReplace);
.replace(SPECIAL_CHARS_REGEXP, function(_, letter, offset) {
return offset ? letter.toUpperCase() : letter;
});
}
/**
+21
View File
@@ -294,6 +294,27 @@ describe('$compile', function() {
inject(function($compile) {});
});
it('should ignore special chars before processing attribute directive name', function() {
// a regression https://github.com/angular/angular.js/issues/16278
module(function() {
directive('t', function(log) {
return {
restrict: 'A',
link: {
pre: log.fn('pre'),
post: log.fn('post')
}
};
});
});
inject(function($compile, $rootScope, log) {
$compile('<div _t></div>')($rootScope);
$compile('<div -t></div>')($rootScope);
$compile('<div :t></div>')($rootScope);
expect(log).toEqual('pre; post; pre; post; pre; post');
});
});
it('should throw an exception if the directive factory is not defined', function() {
module(function() {
expect(function() {