DXF export crashes on valid style attribute

Bug #1216859 reported by Dehalion
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Inkscape
Fix Released
Medium
Alvin Penner

Bug Description

If you save an SVG file containing an element with a style attribute like style="stroke-width: 5;" it works fine, but if there is a space after the semicolon like style="stroke-width: 5; " it crashes with the following stack trace, leaving the exported DXF file empty.

Traceback (most recent call last):
  File "dxf_outlines.py", line 290, in <module>
    e.affect()
  File "C:\Program Files (x86)\Inkscape\share\extensions\inkex.py", line 215, in affect
    self.effect()
  File "dxf_outlines.py", line 281, in effect
    self.process_group(doc)
  File "dxf_outlines.py", line 250, in process_group
    self.process_group(node)
  File "dxf_outlines.py", line 250, in process_group
    self.process_group(node)
  File "dxf_outlines.py", line 250, in process_group
    self.process_group(node)
  File "dxf_outlines.py", line 254, in process_group
    self.process_shape(node, self.groupmat[-1])
  File "dxf_outlines.py", line 167, in process_shape
    style = simplestyle.parseStyle(style)
  File "C:\Program Files (x86)\Inkscape\share\extensions\simplestyle.py", line 179, in parseStyle
    return dict([[x.strip() for x in i.split(":")] for i in s.split(";") if len(i)])
ValueError: dictionary update sequence element #1 has length 1; 2 is required

su_v (suv-lp)
tags: added: dxf exporting
Revision history for this message
su_v (suv-lp) wrote :

Reproduced with Inkscape 0.48+devel r12487 on OS X 10.7.5:
A trailing '; ' in the 'style' attribute of an object caused DXF export to fail (script error). Any occurrences of the same sequence of characters ('; ') within the style attribute string OTOH do not trigger the error in the python script.

AFAICT it is not possible to create such a style attribute (with a trailing '; ') from within Inkscape (new document, default prefs): any whitespace occurring after a ';' in the style attribute string is immediately removed on 'Set' in the XML Editor, and if a ';' remains as trailing character, it is removed as well.

Changed in inkscape:
importance: Undecided → Medium
status: New → Confirmed
Revision history for this message
Dehalion (mail-launchpad) wrote :

style="stroke: red; stroke-width: 5;"
gets split to
["stroke: red", " stroke-width: 5"]
and then to
[["stroke", "red"], ["stroke-width", "5"]]
which is correct.

style="stroke: red; stroke-width: 5; "
gets split to
["stroke: red", " stroke-width: 5", " "]
and then to
[["stroke", "red"], ["stroke-width", "5"], [" "]]
which causes the error because the last element only has one element, two are expected.

I don't know if it is possible to create such a style attribute, but it is definitely possible to open a file with such style attributes and then try to export it triggering this error. The style attributes are not changed (at least until you change a style).

Revision history for this message
Alvin Penner (apenner) wrote :

attached is a modified version of the file simplestyle.py. Could you try this and see if it helps? I've added an extra strip command to remove this blank. You'll need to put this into the directory Inkscape\share\extensions\.

Revision history for this message
su_v (suv-lp) wrote :

Also mentioned as known issue (comment #2) in
- Bug #837603 “Simplestyle extension helper breaks on spaces in styles (with fix)”
  <https://bugs.launchpad.net/inkscape/+bug/837603>

<quote>
Of course, there are still edge cases falling through the cracks: namely a final space at the end of the style. It could be fixed by changing len(i) to len(i.strip()) or changing s.split(";") to s.strip().split(";")

It might be worth considering writing an actual parser instead of a one-liner.
</quote>

su_v (suv-lp)
tags: added: extensions-plugins styles
jazzynico (jazzynico)
Changed in inkscape:
assignee: nobody → Alvin Penner (apenner)
milestone: none → 0.49
status: Confirmed → In Progress
tags: added: backport-proposed
Revision history for this message
jazzynico (jazzynico) wrote :

Fix tested successfully on Debian stable (Crunchbang Waldorf), with Inkscape trunk revision 12493.

Revision history for this message
Alvin Penner (apenner) wrote :

committed to rev 12496

Changed in inkscape:
status: In Progress → Fix Committed
Revision history for this message
su_v (suv-lp) wrote :

Setting milestone to 0.48.5 so that we don't forget to backport.

Changed in inkscape:
milestone: 0.49 → 0.48.5
status: Fix Committed → In Progress
Revision history for this message
su_v (suv-lp) wrote :

Backported to lp:inkscape/0.48.x in revision 9959.

Changed in inkscape:
status: In Progress → Fix Committed
Kris (kris-degussem)
tags: removed: backport-proposed
Changed in inkscape:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.