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

Commit 8e1276c

Browse files
frapontillobtford
authored andcommitted
fix($compile): allow interpolations for non-event handlers attrs
Fix wrong behaviour that didn't allow 'data-on' and 'on' element attributes to be interpolated by $compile. The regex now accepts any string beginning with 'on' and with at least one more English letter.
1 parent 6972596 commit 8e1276c

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/ng/compile.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ function $CompileProvider($provide) {
159159
// Ref: http://developers.whatwg.org/webappapis.html#event-handler-idl-attributes
160160
// The assumption is that future DOM event attribute names will begin with
161161
// 'on' and be composed of only English letters.
162-
var EVENT_HANDLER_ATTR_REGEXP = /^(on[a-z]*|formaction)$/;
162+
var EVENT_HANDLER_ATTR_REGEXP = /^(on[a-z]+|formaction)$/;
163163

164164
/**
165165
* @ngdoc function

test/ng/compileSpec.js

+12
Original file line numberDiff line numberDiff line change
@@ -3250,6 +3250,18 @@ describe('$compile', function() {
32503250
$rootScope.$apply();
32513251
expect(element.attr('on-click')).toEqual('javascript:doSomething()');
32523252
}));
3253+
3254+
it('should pass through arbitrary values on "on" and "data-on" attributes', inject(function($compile, $rootScope) {
3255+
element = $compile('<button data-on="{{dataOnVar}}"></script>')($rootScope);
3256+
$rootScope.dataOnVar = 'data-on text';
3257+
$rootScope.$apply();
3258+
expect(element.attr('data-on')).toEqual('data-on text');
3259+
3260+
element = $compile('<button on="{{onVar}}"></script>')($rootScope);
3261+
$rootScope.onVar = 'on text';
3262+
$rootScope.$apply();
3263+
expect(element.attr('on')).toEqual('on text');
3264+
}));
32533265
});
32543266

32553267
describe('iframe[src]', function() {

0 commit comments

Comments
 (0)