mozman / svgwrite

Python Package to write SVG files (UNMAINTAINED)
Other
548 stars 97 forks source link

Validator reject d attribute value, is this the expected behaviour? #102

Closed alexn11 closed 3 years ago

alexn11 commented 3 years ago

The following code raise an error:

import svgwrite
v = svgwrite.validator2.Full11Validator()
d = "M271.1,127.1c0,3.6-2.6,6.5-5.8,6.5s-5.8-2.9-5.8-6.5,2.6-6.4,5.8-6.4,5.8,2.9,5.8,6.4"
v.check_svg_attribute_value('path', 'd', d)

messages:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.9/site-packages/svgwrite/validator2.py", line 62, in check_svg_attribute_value
    self._check_svg_value(elementname, attributename, value)
  File "/usr/lib/python3.9/site-packages/svgwrite/validator2.py", line 79, in _check_svg_value
    raise TypeError("'%s' is not a valid value for attribute '%s' at svg-element <%s>." % (value, attributename, elementname))
TypeError: 'M271.1,127.1c0,3.6-2.6,6.5-5.8,6.5s-5.8-2.9-5.8-6.5,2.6-6.4,5.8-6.4,5.8,2.9,5.8,6.4' is not a valid value for attribute 'd' at svg-element <path>.

I've copied the value of d from the output of an online "SVG Sanitizer". I've come with the same issue while trying to save a svg file using the module, but I have no idea whats wrong with the value of d:

>>> v.check_svg_attribute_value('path', 'd', "46.33974596215561, 66.0   A 10.0 10.0 -0.0 0,0 63.660254037844375 66.0")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.9/site-packages/svgwrite/validator2.py", line 62, in check_svg_attribute_value
    self._check_svg_value(elementname, attributename, value)
  File "/usr/lib/python3.9/site-packages/svgwrite/validator2.py", line 79, in _check_svg_value
    raise TypeError("'%s' is not a valid value for attribute '%s' at svg-element <%s>." % (value, attributename, elementname))
TypeError: '46.33974596215561, 66.0   A 10.0 10.0 -0.0 0,0 63.660254037844375 66.0' is not a valid value for attribute 'd' at svg-element <path>.

Online SVG editors (3 different ones) parse the following code ok, so I don't understand why the validator throw an error:

<svg width="200" height="200" xmlns="http://www.w3.org/2000/svg">
  <path d=" M 46.33974596215561, 66.0   A 10.0 10.0 -0.0 0,0 63.660254037844375 66.0"></path>
</svg>
alexn11 commented 3 years ago

Validator rejects d string starting with spaces.