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

when clicking on SVG diagrams with links I get: TypeError: Object #<SVGAnimatedString> has no method 'indexOf' #5198

Closed
jstrachan opened this issue Nov 29, 2013 · 8 comments

Comments

@jstrachan
Copy link

pull request on its way...

jstrachan added a commit to jstrachan/angular.js that referenced this issue Nov 29, 2013
…exOf' when clicking on an SVG diagram with links

a minor patch to check a url is a string before attempting to call indexOf() on it to avoid barfing on SVGAnimatedString

fixes angular#5198
jstrachan added a commit to hawtio/hawtio that referenced this issue Nov 29, 2013
@snostorm
Copy link

+1, got this error today myself

@ghost ghost assigned IgorMinar Dec 6, 2013
@IgorMinar
Copy link
Contributor

@jstrachan please submit a plunker/jsfiddle or PR with a test. thanks!

@ghost ghost assigned jeffbcross Dec 9, 2013
@jeffbcross
Copy link
Contributor

@jstrachan is your pull request still in progress? Would it be too much trouble to put together a plunker demonstrating the issue?

@jstrachan
Copy link
Author

@jeffbcross phew - managed to recreate it in a plunker
http://plnkr.co/edit/l09WSkJt0B3s6kROeKal?p=preview

basically if you use $location then have an SVG diagram with any elements inside and you click on the SVG diagram it generates the TypeError in the JavaScript console

@jstrachan
Copy link
Author

@jeffbcross incidentally the HTML is a little bigger than is required ;) e.g. you can ignore the <style> element and the details of the tree; other than just its a shape with an element inside - then its the presence of $location in the controller that causes the bug

@ghost ghost assigned jeffbcross Dec 18, 2013
@jeffbcross
Copy link
Contributor

Thanks! I was able to reproduce the issue. I'm a little slammed this week, but hopefully I can take a look at a fix soon (or review a PR if you submit one).

@caitp
Copy link
Contributor

caitp commented Dec 18, 2013

I think the issue here is the htmlAnchorDirective (https://github.com/angular/angular.js/blob/master/src/ng/directive/a.js) --- It might be possible to detect that it's an svg element (does the node get an appropriate namespace?) and adjust its behaviour. I might run some tests to see real quick, but I'm not totally sure --- actually, it probably isn't even related to that directive, hmm. well, I'll take a quick look, yeah it's in the location click handler.

So basically, we get an SVGAnimatedString, which gives us "baseVal" and "animVal", where "baseVal" is the value before applying transformations, and "animVal" is either equal to "baseVal" if not animated, or the current transformed state.

I really can't decide if it's more appropriate to use animVal or baseVal there! But I guess it's important to get the proper value out of it.

Or maybe just abort if href is an SVGAnimatedString?

Anyways, this is kind of painful because the SVGAnimatedString doesn't give us the absolute href as parsed by the browser. Maybe it would be better to just skip handling these SVGAElement links all together.

@caitp
Copy link
Contributor

caitp commented Dec 18, 2013

Well there's my shot at it, maybe it could/should be handled differently. Let me know

jamesdaily pushed a commit to jamesdaily/angular.js that referenced this issue Jan 27, 2014
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 angular#5472
Closes angular#5198
Closes angular#5199
Closes angular#4098
Closes angular#1420
jamesdaily pushed a commit to jamesdaily/angular.js that referenced this issue Jan 27, 2014
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 angular#5472
Closes angular#5198
Closes angular#5199
Closes angular#4098
Closes angular#1420
jstrachan added a commit to hawtio/hawtio that referenced this issue Jan 27, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants