From 8e6e3ebad991eaf57a7885549ea3b91932d495c9 Mon Sep 17 00:00:00 2001 From: Jamie Mason Date: Wed, 18 Sep 2013 15:00:34 +0100 Subject: [PATCH] fix($compile): ng-attr to support dash separated attribute names --- src/ng/compile.js | 2 +- test/jqLiteSpec.js | 3 ++- test/ng/compileSpec.js | 29 +++++++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/ng/compile.js b/src/ng/compile.js index 2dd0e6ea9699..4f466292d2c6 100644 --- a/src/ng/compile.js +++ b/src/ng/compile.js @@ -631,7 +631,7 @@ function $CompileProvider($provide) { // support ngAttr attribute binding ngAttrName = directiveNormalize(name); if (NG_ATTR_BINDING.test(ngAttrName)) { - name = ngAttrName.substr(6).toLowerCase(); + name = snake_case(ngAttrName.substr(6), '-'); } var directiveNName = ngAttrName.replace(/(Start|End)$/, ''); diff --git a/test/jqLiteSpec.js b/test/jqLiteSpec.js index e6e3a2ac3570..081006584a3a 100644 --- a/test/jqLiteSpec.js +++ b/test/jqLiteSpec.js @@ -1366,6 +1366,7 @@ describe('jqLite', function() { expect(camelCase('-moz-foo-bar')).toBe('MozFooBar'); expect(camelCase('-webkit-foo-bar')).toBe('webkitFooBar'); expect(camelCase('-webkit-foo-bar')).toBe('webkitFooBar'); - }) + }); }); + }); diff --git a/test/ng/compileSpec.js b/test/ng/compileSpec.js index 6b3a04796604..1e66b49fa924 100755 --- a/test/ng/compileSpec.js +++ b/test/ng/compileSpec.js @@ -3342,6 +3342,35 @@ describe('$compile', function() { expect(element.attr('test3')).toBe('Misko'); expect(element.attr('test4')).toBe('Misko'); })); + + describe('when an attribute has a dash-separated name', function () { + + it('should work with different prefixes', inject(function($compile, $rootScope) { + $rootScope.name = "JamieMason"; + element = $compile('')($rootScope); + expect(element.attr('dash-test')).toBeUndefined(); + expect(element.attr('dash-test2')).toBeUndefined(); + expect(element.attr('dash-test3')).toBeUndefined(); + $rootScope.$digest(); + expect(element.attr('dash-test')).toBe('JamieMason'); + expect(element.attr('dash-test2')).toBe('JamieMason'); + expect(element.attr('dash-test3')).toBe('JamieMason'); + })); + + it('should work if they are prefixed with x- or data-', inject(function($compile, $rootScope) { + $rootScope.name = "JamieMason"; + element = $compile('')($rootScope); + expect(element.attr('dash-test2')).toBeUndefined(); + expect(element.attr('dash-test3')).toBeUndefined(); + expect(element.attr('dash-test4')).toBeUndefined(); + $rootScope.$digest(); + expect(element.attr('dash-test2')).toBe('JamieMason'); + expect(element.attr('dash-test3')).toBe('JamieMason'); + expect(element.attr('dash-test4')).toBe('JamieMason'); + })); + + }); + });