diff --git a/src/ng/compile.js b/src/ng/compile.js index 561bb13fef16..4ec3ea5d6d94 100644 --- a/src/ng/compile.js +++ b/src/ng/compile.js @@ -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; + }); } /** diff --git a/test/ng/compileSpec.js b/test/ng/compileSpec.js index 2890a76ac0c0..ca2d43380e8f 100644 --- a/test/ng/compileSpec.js +++ b/test/ng/compileSpec.js @@ -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('
')($rootScope); + $compile('
')($rootScope); + $compile('
')($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() {