Skip to content

Commit

Permalink
fix(a): workaround IE bug affecting mailto urls
Browse files Browse the repository at this point in the history
Apparently there is a really weird bug in IE6-8 that causes anchor textContent
to be reset with href content when both contain @ symbol.

Inserting a bogus comment node into all anchor elements in IE works around this
browser bug.

I'm fixing the issue via directive because that way we'll fix it for jQuery as
well.

I fixed an e2e test too because it was incorrect.

Closes angular#1949
  • Loading branch information
IgorMinar committed Feb 15, 2013
1 parent 37bdcc9 commit 8dea6f1
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 9 deletions.
18 changes: 14 additions & 4 deletions src/ng/directive/a.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,20 @@
var htmlAnchorDirective = valueFn({
restrict: 'E',
compile: function(element, attr) {
// turn <a href ng-click="..">link</a> into a link in IE
// but only if it doesn't have name attribute, in which case it's an anchor
if (!attr.href) {
attr.$set('href', '');

if (msie <= 8) {

// turn <a href ng-click="..">link</a> into a stylable link in IE
// but only if it doesn't have name attribute, in which case it's an anchor
if (!attr.href && !attr.name) {
attr.$set('href', '');
}

// add a comment node to anchors to workaround IE bug that causes element content to be reset
// to new attribute content if attribute is updated with value containing @ and element also
// contains value with @
// see issue #1949
element.append(document.createComment('IE fix'));
}

return function(scope, element) {
Expand Down
2 changes: 1 addition & 1 deletion src/ng/directive/booleanAttrs.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
it('should execute ng-click but not reload when no href but name specified', function() {
element('#link-5').click();
expect(input('value').val()).toEqual('5');
expect(element('#link-5').attr('href')).toBe('');
expect(element('#link-5').attr('href')).toBe(undefined);
});
it('should only change url when only ng-href', function() {
Expand Down
23 changes: 19 additions & 4 deletions test/ng/directive/aSpec.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
'use strict';

describe('a', function() {
var element;
var element, $compile, $rootScope;


beforeEach(inject(function(_$compile_, _$rootScope_) {
$compile = _$compile_;
$rootScope = _$rootScope_;
}));


afterEach(function(){
dealoc(element);
});


it('should prevent default action to be executed when href is empty',
inject(function($rootScope, $compile) {
it('should prevent default action to be executed when href is empty', function() {
var orgLocation = document.location.href,
preventDefaultCalled = false,
event;
Expand Down Expand Up @@ -42,5 +47,15 @@ describe('a', function() {
}

expect(document.location.href).toEqual(orgLocation);
}));
});


it('should prevent IE for changing text content when setting attribute', function() {
// see issue #1949
element = jqLite('<a href="">hello@you</a>');
$compile(element);
element.attr('href', 'bye@me');

expect(element.text()).toBe('hello@you');
});
});

0 comments on commit 8dea6f1

Please sign in to comment.