The general rule for error handling in path data is that the SVG user agent shall render a ‘path’ element up to (but not including) the path command containing the first error in the path data specification. This will provide a visual clue to the user or developer about where the error might be in the path data specification. This rule will greatly discourage generation of invalid SVG path data.
If a path data command contains an incorrect set of parameters, then the given path data command is rendered up to and including the last correctly defined path segment, even if that path segment is a sub-component of a compound path data command, such as a "lineto" with several pairs of coordinates. For example, for the path data string 'M 10,10 L 20,20,30', there is an odd number of parameters for the "L" command, which requires an even number of parameters. The user agent is required to draw the line from (10,10) to (20,20) and then perform error reporting since 'L 20 20' is the last correctly defined segment of the path data specification.
Wherever possible, all SVG user agents shall report all errors to the user.
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'
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 callparse()
on that object and have the object contain as much of the file as was legally parsed. The paths themselves already cover this.