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

Commit c4003fd

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 ab856d8 commit c4003fd

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
@@ -3671,7 +3671,9 @@ var SPECIAL_CHARS_REGEXP = /[:\-_]+(.)/g;
36713671
function directiveNormalize(name) {
36723672
return name
36733673
.replace(PREFIX_REGEXP, '')
3674-
.replace(SPECIAL_CHARS_REGEXP, fnCamelCaseReplace);
3674+
.replace(SPECIAL_CHARS_REGEXP, function(_, letter, offset) {
3675+
return offset ? letter.toUpperCase() : letter;
3676+
});
36753677
}
36763678

36773679
/**

test/ng/compileSpec.js

+21
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,27 @@ describe('$compile', function() {
305305
inject(function($compile) {});
306306
});
307307

308+
it('should ignore special chars before processing attribute directive name', function() {
309+
// a regression https://github.com/angular/angular.js/issues/16278
310+
module(function() {
311+
directive('t', function(log) {
312+
return {
313+
restrict: 'A',
314+
link: {
315+
pre: log.fn('pre'),
316+
post: log.fn('post')
317+
}
318+
};
319+
});
320+
});
321+
inject(function($compile, $rootScope, log) {
322+
$compile('<div _t></div>')($rootScope);
323+
$compile('<div -t></div>')($rootScope);
324+
$compile('<div :t></div>')($rootScope);
325+
expect(log).toEqual('pre; post; pre; post; pre; post');
326+
});
327+
});
328+
308329
it('should throw an exception if the directive factory is not defined', function() {
309330
module(function() {
310331
expect(function() {

0 commit comments

Comments
 (0)