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

Commit 12cf994

Browse files
curlydevilNarretz
authored andcommitted
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 73050cd) Closes #16314 Closes #16278
1 parent 873e263 commit 12cf994

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/ng/compile.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -3647,7 +3647,9 @@ var SPECIAL_CHARS_REGEXP = /[:\-_]+(.)/g;
36473647
function directiveNormalize(name) {
36483648
return name
36493649
.replace(PREFIX_REGEXP, '')
3650-
.replace(SPECIAL_CHARS_REGEXP, fnCamelCaseReplace);
3650+
.replace(SPECIAL_CHARS_REGEXP, function(_, letter, offset) {
3651+
return offset ? letter.toUpperCase() : letter;
3652+
});
36513653
}
36523654

36533655
/**

test/ng/compileSpec.js

+21
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,27 @@ describe('$compile', function() {
294294
inject(function($compile) {});
295295
});
296296

297+
it('should ignore special chars before processing attribute directive name', function() {
298+
// a regression https://github.com/angular/angular.js/issues/16278
299+
module(function() {
300+
directive('t', function(log) {
301+
return {
302+
restrict: 'A',
303+
link: {
304+
pre: log.fn('pre'),
305+
post: log.fn('post')
306+
}
307+
};
308+
});
309+
});
310+
inject(function($compile, $rootScope, log) {
311+
$compile('<div _t></div>')($rootScope);
312+
$compile('<div -t></div>')($rootScope);
313+
$compile('<div :t></div>')($rootScope);
314+
expect(log).toEqual('pre; post; pre; post; pre; post');
315+
});
316+
});
317+
297318
it('should throw an exception if the directive factory is not defined', function() {
298319
module(function() {
299320
expect(function() {

0 commit comments

Comments
 (0)