From 8e0bf800bf59a809c9774e34656849f3ef515b32 Mon Sep 17 00:00:00 2001 From: Jeff Schiller Date: Thu, 18 Feb 2010 01:34:29 +0000 Subject: [PATCH] Fix Issue 486: Remove uses without href to prevent Safari crash. Turns all unit tests green git-svn-id: http://svg-edit.googlecode.com/svn/trunk@1408 eee81c28-f429-11dd-99c0-75d572ba1ddd --- editor/svg-editor.html | 11 ----------- editor/svgcanvas.js | 5 +++++ test/test1.html | 9 ++++++--- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/editor/svg-editor.html b/editor/svg-editor.html index 099fd905..c3d8fb05 100644 --- a/editor/svg-editor.html +++ b/editor/svg-editor.html @@ -45,17 +45,6 @@ script type="text/javascript" src="locale/locale.min.js"> SVG-edit - - -
- -
diff --git a/editor/svgcanvas.js b/editor/svgcanvas.js index 12209a90..f6f3dab7 100644 --- a/editor/svgcanvas.js +++ b/editor/svgcanvas.js @@ -1385,6 +1385,11 @@ function BatchCommand(text) { } } + // Safari crashes on a without a xlink:href, so we just remove the node here + if (node.nodeName == "use" && !node.getAttributeNS(xlinkns,"href")) { + parent.removeChild(node); + return; + } // if the element has attributes pointing to a non-local reference, // need to remove the attribute $.each(["clip-path", "fill", "marker-end", "marker-mid", "marker-start", "mask", "stroke"],function(i,attr) { diff --git a/test/test1.html b/test/test1.html index c28be868..b29589d2 100644 --- a/test/test1.html +++ b/test/test1.html @@ -124,19 +124,22 @@ module("Import Module"); test("Test import use", function() { - expect(2); + expect(3); svgCanvas.setSvgString("" + "" + "" + "" + + "" + ""); var u = document.getElementById("the-use"), - fu = document.getElementById("foreign-use"); + fu = document.getElementById("foreign-use"), + nfu = document.getElementById("no-use"); equals((u && u.nodeName == "use"), true, "Did not import element"); - equals((fu && !fu.getAttributeNS(xlinkns,"href")), true, "Did not remove reference to foreign element in "); + equals(fu, null, "Removed element that had a foreign href"); + equals(nfu, null, "Removed element that had no href"); }); test("Test getUrlFromAttr", function() {