1. Dinu Gherman
  2. svglib
  3. Issues
Issue #2 new

Handle empty nodes gracefully

Anonymous created an issue

When an empty node is passed to Svg2RlgShapeConverter.convertPath then an IndexError is raised at line 1009. example TraceBack:

{{{

svglib.svg2rlg('myfile.svg') Traceback (most recent call last): File "<stdin>", line 1, in <module> File "svglib.py", line 1176, in svg2rlg svgRenderer.render(svg) File "svglib.py", line 509, in render self.render(child, self.mainGroup) File "svglib.py", line 532, in render item = self.renderG(n) File "svglib.py", line 624, in renderG item = self.render(child, parent=gr) File "svglib.py", line 552, in render shape = getattr(self.shapeConverter, methodName)(n) File "svglib.py", line 1009, in convertPath if ops[-1] == 3: IndexError: list index out of range }}}

Here's a patch I porpose to fix the problem.

{{{ --- svglib.py 2012-08-27 16:04:16.000000000 +0200 +++ svglib_new.py 2012-08-27 16:04:23.000000000 +0200 @@ -875,7 +875,10 @@ normPath = normaliseSvgPath(d) pts, ops = [], [] lastMoveToOp = None - +
+ if not normPath: + return +
for i in xrange(0, len(normPath), 2): op, nums = normPath[i:i+2] }}}

Regards

Pier Maria Mattioli

Comments (3)

  1. Log in to comment