Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deep cloning of SVG node loses xlink namespace information #1601

Closed
pkra opened this issue Sep 15, 2016 · 5 comments
Closed

deep cloning of SVG node loses xlink namespace information #1601

pkra opened this issue Sep 15, 2016 · 5 comments

Comments

@pkra
Copy link

pkra commented Sep 15, 2016

When deep cloning an SVG, the xlink namespace information gets mangled.
This can lead to rendering issues (e.g., FF and Safari will fail to look up the use target).

Minimal example (tested on jsdom v9.5.0):

jsdom = require('jsdom'); 
doc = jsdom.jsdom();
doc.body.innerHTML = "<svg xmlns:xlink='http://www.w3.org/1999/xlink'><use xlink:href='#test'></use></svg>";
var clone = doc.body.firstChild.cloneNode(true);
console.log(clone.outerHTML);
// expected:
//<svg xmlns:xlink="http://www.w3.org/1999/xlink"><use xlink:href="#test"></use></svg>
// result: 
//<svg xlink="http://www.w3.org/1999/xlink"><use href="#test"></use></svg>

This seems similar to #861.

@pkra
Copy link
Author

pkra commented Sep 15, 2016

Note this can be worked around by using the original's outerHTML to build a clone manually.

@Sebmaster
Copy link
Member

Are you sure this only occurs after the deepClone? If you print outer html before the clone, I'd expect the XML attributes to get mangled in a similar way, since we only serialise to html (even though we parse XML (kinda) correctly).

@pkra
Copy link
Author

pkra commented Sep 15, 2016

If you print outer html before the clone, I'd expect the XML attributes to get mangled in a similar way, since we only serialise to html (even though we parse XML (kinda) correctly).

What you are describing is just #861, right? (Which was fixed). To answer your question, I'm using outerHTML as a workaround in a project so I'm reasonably certain it works.

@pkra
Copy link
Author

pkra commented Sep 15, 2016

FYI, if you add console.log(doc.body.firstChild.outerHTML); to the minimal example, its result is correct.

@pkra
Copy link
Author

pkra commented Oct 3, 2016

Thanks so much, @domenic !

nhunzaker pushed a commit to nhunzaker/jsdom that referenced this issue Dec 22, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants