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

Commit

Permalink
fix($compile): allow interpolations for non-event handlers attrs
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
frapontillo authored and btford committed Oct 1, 2013
1 parent 6972596 commit 8e1276c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ng/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ function $CompileProvider($provide) {
// Ref: http://developers.whatwg.org/webappapis.html#event-handler-idl-attributes
// The assumption is that future DOM event attribute names will begin with
// 'on' and be composed of only English letters.
var EVENT_HANDLER_ATTR_REGEXP = /^(on[a-z]*|formaction)$/;
var EVENT_HANDLER_ATTR_REGEXP = /^(on[a-z]+|formaction)$/;

/**
* @ngdoc function
Expand Down
12 changes: 12 additions & 0 deletions test/ng/compileSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3250,6 +3250,18 @@ describe('$compile', function() {
$rootScope.$apply();
expect(element.attr('on-click')).toEqual('javascript:doSomething()');
}));

it('should pass through arbitrary values on "on" and "data-on" attributes', inject(function($compile, $rootScope) {
element = $compile('<button data-on="{{dataOnVar}}"></script>')($rootScope);
$rootScope.dataOnVar = 'data-on text';
$rootScope.$apply();
expect(element.attr('data-on')).toEqual('data-on text');

element = $compile('<button on="{{onVar}}"></script>')($rootScope);
$rootScope.onVar = 'on text';
$rootScope.$apply();
expect(element.attr('on')).toEqual('on text');
}));
});

describe('iframe[src]', function() {
Expand Down

0 comments on commit 8e1276c

Please sign in to comment.