svg / svgo

⚙️ Node.js tool for optimizing SVG files
https://svgo.dev/
MIT License
21.04k stars 1.39k forks source link

Unbound namespace prefix: "xlink" #1979

Closed C0rn3j closed 6 months ago

C0rn3j commented 7 months ago
Svgo error: SvgoParserError: /home/c0rn3j/test/test2/test.svg:131:75: Unbound namespace prefix: "xlink"

  129 | …AiApdN6YEc/gImVA9zMAHrmg0PnL0Fq2gEQQLSdZv3/PwFYgT1ATFZT
  130 | …qQlC+py/qe6BwACiC4IlJSA9cR9WpgNEED0meT7/78AWJU50MJogAAD
> 131 | …kSuQmCC" transform="matrix(1 0 0 1 29.6089 74.2822)"/>
      |                                                       ^
  132 | …;" d="M70.289,125.826c-8.642-0.817-15.063,4.922-15.063,4.922s-0.006-0.012-…
  133 | …height="57" xlink:href="data:;base64,iVBORw0KGgoAAAANSUhEUgAAAB4AAAA7CAYAA…

is 3.2.0 intended to throw this error?

Judging by https://github.com/svg/svgo/issues/1730#issuecomment-1876093453 it seems there's a plugin that can at least convert it to SVG 2.0, either this is a different bug, or the error message should be providing more information

My attempt to use https://svgo.dev/docs/plugins/remove-xlink/ led to the same error however.

zip'd file in question: test.zip

Desktop (please complete the following information):

SethFalco commented 6 months ago

It is meant to throw an error in this case. Your SVG is malformed, and should only work in browsers as they ignore namespaces. Can you confirm if this is the raw output from Illustrator, or did you either manually or through another tool manipulate this SVG already? 🤔

Meanwhile, you could make one of two changes to resolve the issue.

If you have any other questions or feedback, you're welcome to respond here!

Add XLink Namespace

Add the XLink namespace, which would be better for compatibility. You can do this be replacing the line that opens the <svg> tag to include the XLink namespace.

<svg width="147.717pt" height="151.179pt" viewBox="0 0 147.717 151.179" xml:space="preserve" xmlns:xlink="http://www.w3.org/1999/xlink">

Migrate from XLink:href to href

Replace all instances of xlink:href with just href. This attribute is an SVG 2 property though, and so may impact compatibility.

C0rn3j commented 6 months ago

Judging by the fact this was Adobe Illustrator 9.0 released in 2000 I'll chalk it up to the SVG being broken due to ancient software, I did not create this.

This was svgz'd and I undid that, I can't seem to find where I even found it at this point (oxsc-app-shell.svgz)