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

Commit bc3ff2c

Browse files
Caitlin PotterIgorMinar
Caitlin Potter
authored andcommitted
fix($location): parse xlink:href for SVGAElements
Before this fix, the xlink:href property of an SVG <a> element could not be parsed on click, as the property is an SVGAnimatedString rather than a DOMString. This patch parses the xlink:href's animVal into a DOMString in order to prevent an `Object #<SVGAnimatedString> has no method 'indexOf'` exception from being thrown, and also to update the location if necessary as expected. Closes #5472 Closes #5198 Closes #5199 Closes #4098 Closes #1420
1 parent 8f329ff commit bc3ff2c

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/ng/location.js

+7
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,13 @@ function $LocationProvider(){
629629
}
630630

631631
var absHref = elm.prop('href');
632+
633+
if (isObject(absHref) && absHref.toString() === '[object SVGAnimatedString]') {
634+
// SVGAnimatedString.animVal should be identical to SVGAnimatedString.baseVal, unless during
635+
// an animation.
636+
absHref = urlResolve(absHref.animVal).href;
637+
}
638+
632639
var rewrittenUrl = $location.$$rewrite(absHref);
633640

634641
if (absHref && !elm.attr('target') && rewrittenUrl && !event.isDefaultPrevented()) {

test/ng/locationSpec.js

+25
Original file line numberDiff line numberDiff line change
@@ -1229,6 +1229,31 @@ describe('$location', function() {
12291229
});
12301230
browserTrigger(button, 'click');
12311231
}));
1232+
1233+
1234+
it('should not throw when clicking an SVGAElement link', function() {
1235+
var base;
1236+
module(function($locationProvider) {
1237+
return function($browser) {
1238+
window.location.hash = '!someHash';
1239+
$browser.url(base = window.location.href);
1240+
base = base.split('#')[0];
1241+
$locationProvider.hashPrefix('!');
1242+
}
1243+
});
1244+
inject(function($rootScope, $compile, $browser, $rootElement, $document, $location) {
1245+
// we need to do this otherwise we can't simulate events
1246+
$document.find('body').append($rootElement);
1247+
var template = '<svg><g><a xlink:href="#!/view1"><circle r="50"></circle></a></g></svg>';
1248+
var element = $compile(template)($rootScope);
1249+
1250+
$rootElement.append(element);
1251+
var av1 = $rootElement.find('a').eq(0);
1252+
expect(function() {
1253+
browserTrigger(av1, 'click');
1254+
}).not.toThrow();
1255+
});
1256+
});
12321257
});
12331258

12341259

0 commit comments

Comments
 (0)