meerk40t / svgelements

SVG Parsing for Elements, Paths, and other SVG Objects.
MIT License
124 stars 28 forks source link

SVG.parse() may violate SVG 2.0 9.4.5 #217

Closed tatarize closed 1 year ago

tatarize commented 1 year ago

https://www.w3.org/TR/SVG2/paths.html#PathDataErrorHandling

Specifically,

SVG.parse() is effectively a shorthand static function that parses an svg file and returns an SVG. However, we should be able to specify a SVG() file then call parse() on that object and have the object contain as much of the file as was legally parsed. The paths themselves already cover this.

>>> p = Path()
>>> p.parse("M 10 10 L 20 20 L NaN NaN")
Traceback (most recent call last):
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2022.3.3\plugins\python-ce\helpers\pydev\pydevconsole.py", line 364, in runcode
    coro = func()
  File "<input>", line 1, in <module>
  File "C:\Users\Tat\PycharmProjects\svgelements\svgelements\svgelements.py", line 5924, in parse
    tokens.parse(self, pathdef)
  File "C:\Users\Tat\PycharmProjects\svgelements\svgelements\svgelements.py", line 390, in parse
    raise ValueError
ValueError
>>> p.d()
'M 10,10 L 20,20'