meerk40t / svgelements

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

REGEX_CSS_STYLE parse fails parsing with comments. #174

Closed tatarize closed 1 year ago

tatarize commented 2 years ago

assignments = list(re.findall(REGEX_CSS_STYLE, elem.text))

  File "meerk40t\svgelements.py", line 8754, in parse
  File "re.py", line 225, in findall
TypeError: expected string or bytes-like object

I believe this might be caused if elem.text is None. This would imply:

<style/>

As a tag could cause a crash.


CSS does not properly match and exclude CSS comments.

\/\*[\s\S]*?\*\/|\/\/.*$
aliflux-omo commented 1 year ago

Issue popping up again when using some wikipedia SVGs.

E.g. https://upload.wikimedia.org/wikipedia/commons/5/58/Axis_Occupation_of_Europe_%281942%29.svg

tatarize commented 1 year ago

Issue popping up again when using some wikipedia SVGs.

E.g. https://upload.wikimedia.org/wikipedia/commons/5/58/Axis_Occupation_of_Europe_%281942%29.svg

<style
type="text/css"
id="style10" />

This isn't really comments in the style but related since it's trying to strip the CSS Comment with a regex. The issue here is that for some random reason the Wikipedia svg in question has no style text. It's an empty style tag conveying no information. This wasn't accounted for and tries to apply the strip the comments from a None value. This isn't so much more of the same bug but a bug caused by this solution.

tatarize commented 1 year ago

image The rest seems fairly fine. I'll post the patch shortly.

aliflux-omo commented 1 year ago

Yes you're right. Temporarily, my solution is to parse the svg as xml, check for empty style tags, remove it, save it to svg. Then load it to svgelements lib

But it would be better if you could handle this case internally

tatarize commented 1 year ago

This was fixed in 1.7.4.