Skip to content

SVG: draw polygon and polyline points up to the last complete pair - #2000

Merged
andersonhc merged 2 commits into
py-pdf:masterfrom
RavSinghChandan:svg-polygon-incomplete-points
Oct 11, 2026
Merged

andersonhc merged 2 commits into
py-pdf:masterfrom
RavSinghChandan:svg-polygon-incomplete-points

Conversation

@RavSinghChandan

@RavSinghChandan RavSinghChandan commented Oct 11, 2026 •

Copy link
Copy Markdown

A <polygon> or <polyline> with an odd number of coordinates (like points="0,0 10,10 20") or empty points crashed with IndexError: pop from empty list. The SVG spec says to draw up to the last complete pair, and draw nothing for empty points. Now it does that. Valid shapes draw the same as before. Added tests.

e.g. Fixes #0

Checklist:

  • A unit test is covering the code added / modified by this PR

  • In case of a new feature, docstrings have been added, with also some documentation in the docs/ folder

  • A mention of the change is present in CHANGELOG.md

  • This PR is ready to be merged

By submitting this pull request, I confirm that my contribution is made under the terms of the GNU LGPL 3.0 license.

Comment thread fpdf/svg.py Resolved
@RavSinghChandan

Copy link
Copy Markdown
Author

Good catch, thanks! It now reads the points in order and stops at the first error, so nothing after it is drawn: "1,0 10,10 x 20,20" draws only up to 10,10, and a doubled comma stops it the same way. A trailing odd coordinate is still dropped. I added tests for both, which fail on the previous version.

@andersonhc
andersonhc merged commit ab701a5 into py-pdf:master Oct 11, 2026
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants