methodofaction / Method-Draw

Method Draw, the SVG Editor for Method of Action

Home Page:http://editor.method.ac

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Attribute xlink:href redefined

kamshory opened this issue · comments

When I place a PNG image in the document, it throws an error "Attribute xlink:href redefined". When I check the tag, there is a duplicate attribute xlink:href.
How to get rid of the duplication?

The Problem

I was able to pin down the issue to line 5355 in src/js/svgcanvas.js.

if (illutratorCompat && str.includes(" href=")) str = str.replace(" href=", " xlink:href=");

If the xml already has an xlink:href attribute AND an href attribute, the href becomes xlink:href.

SVG2 removes the xlink namespace altogether,
and this attribute is now deprecated.

The "real solution" to this would be to figure out how to stop xlink:href from being written in the first place. (I mean, if backwards-compatibility isn't an issue for you)
Oddly enough, removing this line

svgedit.utilities.setHref = function(elem, val) {
  elem.setAttributeNS(XLINKNS, "xlink:href", val); // this
  elem.setAttribute("href", val);
}

and/or this line

    image.setAttributeNS(xlinkns,'xlink:href',url);

doesn't solve it.

Working (but not ideal) Solution

Consider a PR that changes that line to

// make sure we don't already have an `xlink:href` attribute
if (illutratorCompat && str.includes(" href=") && !str.includes(" xlink:href=")) {
   str = str.replace(" href=", " xlink:href=");
  }

or simply "if it has both attributes don't do anything".

It solves the problem but feels hacky and wrong. Plus it might break other workflows?

So currently the entire image Base64 is written twice... once in the href attr and the other in the xlink namespace attr.
the xlink one can obviously be removed in the line after, but it's best not to create it at all.