Yqnn / svg-path-editor

Online editor to create and manipulate SVG paths
https://yqnn.github.io/svg-path-editor/
Apache License 2.0
4.04k stars 326 forks source link

Minification erroneously concats numbers #123

Closed MajorTanya closed 7 months ago

MajorTanya commented 7 months ago

Hi,

while using your website to check some path data I was looking at, I saw the "Minify output" button and I liked it. It worked well for most of my paths, but for some of them, the outputted data wasn't correct anymore.

Example path data: M0 0 a 22.4 35.1 117.8 1 0 20.9 -39.6 a 22.4 35.1 117.8 1 0 -20.9 39.6z

This is correctly displayed as an ellipse near the origin point, and turning the minifier on and off again correctly turns it into this:

M 0 0 a 22.4 35.1 117.8 1 0 20.9 -39.6 a 22.4 35.1 117.8 1 0 -20.9 39.6 z

A fully spaced out path. But when the minifier is turned on, it outputs this:

M0 0a22.4 35.1 117.8 1020.9-39.6 22.4 35.1 117.8 10-20.9 39.6z

This turned the sequences of 1 0 20.9 -39.6 and 1 0 -20.9 into the way larger 1020.9-39.6 and 10-20.9.

I'm not experienced at all with SVG paths (which is why I was very grateful for your tool), so I don't know if the minus sign being right next to the previous number is allowed, but the main issue is the concatenation of the numbers in my case. I didn't notice it at first because the display was still showing the correct ellipse for me and I could manipulate it as normal.

If this ends up not being an issue with your website but some dependency of yours, I apologise. I tried searching through your issues and couldn't find any mention of something similar to this, so I hope I didn't miss something.

Yqnn commented 7 months ago

Hi, Thanks for the report, but this behaviour is actually correct. Specifications: https://www.w3.org/TR/SVG2/paths.html#PathDataBNF

tl;dr : separators are optional when there is no ambiguity. In A X X X 1 0 X X, 1 and 0 are flags, not numbers, so they can be minified to 10X without creating an ambiguity.

MajorTanya commented 7 months ago

Ah sorry, my bad then. Thanks for the clearing up 👍