Whole file

regebro/svg.path

The author described this change as Issue #60: Fix handling of zero length paths (#73). It counts as a record because the check below fails on the code as it stood at c0845d7f6 and passes on 327d4aec2, with nothing else changed between the two runs.

Fix saved2021-03-27
Sharing licenceMIT · LICENSE.txt
Change size+9 1

What the code was meant to do, written into the code itself as a save note

Issue #60: Fix handling of zero length paths (#73)

The change

461461 each.length(error=error, min_depth=min_depth) for each in self._segments
462462 ]
463463 self._length = sum(lengths)
464- self._lengths = [each / self._length for each in lengths]
464+ if self._length == 0:
465+ self._lengths = lengths
466+ else:
467+ self._lengths = [each / self._length for each in lengths]
465468 # Calculate the fractional distance for each segment to use in point()
466469 fraction = 0
467470 for each in self._lengths:
477480 return self._segments[-1].point(pos)
478481
479482 self._calc_lengths(error=error)
483+
484+ # Fix for paths of length 0 (i.e. points)
485+ if self._length == 0:
486+ return self._segments[0].point(0.0)
487+
480488 # Find which segment the point we search for is located on:
481489 i = bisect(self._fractions, pos)
482490 if i == 0:

The check that tells the two apart

failpass·src/svg/path/tests/test_paths.py::TestPath::test_zero_paths

Check file src/svg/path/tests/test_paths.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.

Origin and history

The code before itc0845d7f6f981f34756c1f4c50f4985cd90d18bc
Broken version dated2021-03-27
Modulesvg.path.path
Units changedPath
Fingerprintc2656f4d0729873c
Checked2026-08-18 by goldset/0.1

Every field above is generated by our program. None of it is written by hand.

Other bugs found in regebro/svg.path