blackears / svgSalamander

154 stars 56 forks source link

fails to render minified SVG due to `java.lang.NumberFormatException: For input string: "l"` #77

Closed breunigs closed 3 years ago

breunigs commented 3 years ago

I'm observing the stacktrace from within JOSM (an editor for the OpenStreetMap that uses – as far as I can tell – the version release here: https://github.com/blackears/svgSalamander/issues/70#issuecomment-727639898):

java.lang.NumberFormatException: For input string: "l"
    at java.base/jdk.internal.math.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:2054)
    at java.base/jdk.internal.math.FloatingDecimal.parseFloat(FloatingDecimal.java:122)
    at java.base/java.lang.Float.parseFloat(Float.java:461)
    at com.kitfox.svg.SVGElement.nextFloat(SVGElement.java:822)
    at com.kitfox.svg.SVGElement.parsePathList(SVGElement.java:893)
    at com.kitfox.svg.SVGElement.buildPath(SVGElement.java:946)
    at com.kitfox.svg.Path.build(Path.java:87)
    at com.kitfox.svg.Path.updateTime(Path.java:151)
    at com.kitfox.svg.Group.updateTime(Group.java:313)
    at com.kitfox.svg.SVGRoot.updateTime(SVGRoot.java:400)
    at com.kitfox.svg.SVGDiagram.updateTime(SVGDiagram.java:243)
    at com.kitfox.svg.SVGUniverse.loadSVG(SVGUniverse.java:621)
    at com.kitfox.svg.SVGUniverse.loadSVG(SVGUniverse.java:467)
    at com.kitfox.svg.SVGUniverse.loadSVG(SVGUniverse.java:444)
    at org.openstreetmap.josm.tools.ImageProvider.getIfAvailableLocalURL(ImageProvider.java:1144)
    at org.openstreetmap.josm.tools.ImageProvider.getIfAvailableImpl(ImageProvider.java:933)
(…)

The image in question is this and renders fine in other viewers (it should render a triangle pointing up, with rounded corners):

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 847.156 743.622" width="25" height="25">
  <path d="M423.584.876c-9.394 0-18.784 3.584-25.948 10.748a36.682 36.682 0 00-5.884 7.69l-19.057 32.695h-.088L6.23 687.059c-.068.121-.121.244-.19.366a36.735 36.735 0 00-4.283 9.888c-5.243 19.57 6.373 39.692 25.948 44.936a36.547 36.547 0 009.672 1.25h772.584c20.269 0 36.694-16.426 36.694-36.695 0-6.63-1.767-12.851-4.849-18.223-.024-.038-.044-.077-.067-.121L461.284 27.946c-4.829-8.33-7.065-11.63-11.758-16.322C442.364 4.46 432.974.876 423.584.876z" />
</svg>
blackears commented 3 years ago

The problem is that in the path tags, the arc commands components expect 7 distinct numbers but you are putting fewer. This is due to the seros being specified without spaces around them. I don't know if this is valid syntax or not. If you pad the zeros with spaces, the path parses correctly.

blackears commented 3 years ago

I've pushed a change. You path should parse correctly now.