mathandy / svgpathtools

A collection of tools for manipulating and analyzing SVG Path objects and Bezier curves.
MIT License
557 stars 142 forks source link

Error in the path parsing #185

Open pwichmann opened 2 years ago

pwichmann commented 2 years ago

Many thanks for a useful library.

I think the path parsing methods still contain errors: The following path is a valid SVG path: M12 22a10 10 0 110-20 10 10 0 010 20z. It is a minified path with two consecutive a commands. In those cases, the repeated a can be omitted. Furthermore, the binary flags can be written without separating whitespace.

The path can be visualised using this neat tool: https://svg-path-visualizer.netlify.app/#M12%2022a10%2010%200%20110-20%2010%2010%200%20010%2020z

However, it cannot be parsed by svgpathtools.

File "/Users/pascalwichmann/anaconda3/envs/stg/lib/python3.9/site-packages/svgpathtools/parser.py", line 15, in parse_path return Path(pathdef, current_pos=current_pos, tree_element=tree_element) File "/Users/pascalwichmann/anaconda3/envs/stg/lib/python3.9/site-packages/svgpathtools/path.py", line 2439, in init self._parse_path(segments[0], current_pos) File "/Users/pascalwichmann/anaconda3/envs/stg/lib/python3.9/site-packages/svgpathtools/path.py", line 3304, in _parse_path arc = float(elements.pop()) ValueError: could not convert string to float: 'z'

I found various other paths that also do not work (but have not checked if the cause is identical).

pwichmann commented 2 years ago

Interestingly, the original svg.path is able to parse it.