abey79 / vpype

The Swiss-Army-knife command-line tool for plotter vector graphics.
https://vpype.readthedocs.io/
MIT License
690 stars 61 forks source link

`read` crashes with SVG containing empty <polygon> tag #260

Closed tatarize closed 3 years ago

tatarize commented 3 years ago

https://github.com/meerk40t/svgelements/issues/105

            if isinstance(elem, svgelements.Polygon):
                path.append(svgelements.Close(elem.points[-1], elem.points[0]))

A polygon of <polygon points=""> in svg creates a polygon of zero points and as such that line causes an index error. I checked the SVG spec for the error handling of 0 point polygons and it says "The initial value, (none), indicates that the polygon element is valid, but does not render." Which means svgelements is in error when it produces a degenerate polygon in that case.

tatarize commented 3 years ago

This will be corrected in svgelements 1.4.11. The parsing somewhat represents the render tree and as such degenerate shapes which are not to be rendered will not be returned as parsed. So Rect with widths of 0 will also be omitted going forward.

abey79 commented 3 years ago

For reference in case someone else encounters this bug, this is the error shown when this happens:

 File "c:\users\ohmar\virtualenvironments\vpype_venv\lib\site-packages\vpype\io.py", line 189, in _extract_paths
    path = [svgelements.Move(elem.points[0]), elem]
IndexError: list index out of range
tatarize commented 3 years ago

1.4.11 was published and should omit degenerate shapes.