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

fix(a): workaround IE bug affecting mailto urls #2013

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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');
});
});