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

Commit 37e8b12

Browse files
committed
fix(a): workaround IE bug affecting mailto urls
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 #1949
1 parent 1ace5eb commit 37e8b12

File tree

3 files changed

+34
-9
lines changed

3 files changed

+34
-9
lines changed

src/ng/directive/a.js

+14-4
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,20 @@
1616
var htmlAnchorDirective = valueFn({
1717
restrict: 'E',
1818
compile: function(element, attr) {
19-
// turn <a href ng-click="..">link</a> into a link in IE
20-
// but only if it doesn't have name attribute, in which case it's an anchor
21-
if (!attr.href) {
22-
attr.$set('href', '');
19+
20+
if (msie <= 8) {
21+
22+
// turn <a href ng-click="..">link</a> into a stylable link in IE
23+
// but only if it doesn't have name attribute, in which case it's an anchor
24+
if (!attr.href && !attr.name) {
25+
attr.$set('href', '');
26+
}
27+
28+
// add a comment node to anchors to workaround IE bug that causes element content to be reset
29+
// to new attribute content if attribute is updated with value containing @ and element also
30+
// contains value with @
31+
// see issue #1949
32+
element.append(document.createComment('IE fix'));
2333
}
2434

2535
return function(scope, element) {

src/ng/directive/booleanAttrs.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
it('should execute ng-click but not reload when no href but name specified', function() {
6767
element('#link-5').click();
6868
expect(input('value').val()).toEqual('5');
69-
expect(element('#link-5').attr('href')).toBe('');
69+
expect(element('#link-5').attr('href')).toBe(undefined);
7070
});
7171
7272
it('should only change url when only ng-href', function() {

test/ng/directive/aSpec.js

+19-4
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
'use strict';
22

33
describe('a', function() {
4-
var element;
4+
var element, $compile, $rootScope;
5+
6+
7+
beforeEach(inject(function(_$compile_, _$rootScope_) {
8+
$compile = _$compile_;
9+
$rootScope = _$rootScope_;
10+
}));
511

612

713
afterEach(function(){
814
dealoc(element);
915
});
1016

1117

12-
it('should prevent default action to be executed when href is empty',
13-
inject(function($rootScope, $compile) {
18+
it('should prevent default action to be executed when href is empty', function() {
1419
var orgLocation = document.location.href,
1520
preventDefaultCalled = false,
1621
event;
@@ -42,5 +47,15 @@ describe('a', function() {
4247
}
4348

4449
expect(document.location.href).toEqual(orgLocation);
45-
}));
50+
});
51+
52+
53+
it('should prevent IE for changing text content when setting attribute', function() {
54+
// see issue #1949
55+
element = jqLite('<a href="">hello@you</a>');
56+
$compile(element);
57+
element.attr('href', 'bye@me');
58+
59+
expect(element.text()).toBe('hello@you');
60+
});
4661
});

0 commit comments

Comments
 (0)