Skip to content

SVG: handle empty path data like a path without d - #2144

Merged
andersonhc merged 1 commit into
py-pdf:masterfrom
RavSinghChandan:svg-empty-path-data
Nov 10, 2026
Merged

andersonhc merged 1 commit into
py-pdf:masterfrom
RavSinghChandan:svg-empty-path-data

Conversation

@RavSinghChandan

Copy link
Copy Markdown

A <path d=""> fails with ValueError: Path does not start with move item. SVG says empty path data disables rendering of the path; it is not an error.

This comes from real tools: PyMuPDF's Page.get_svg_image() writes <path d=""/> for empty clips (its test output tests/test_4846_out.svg fails to load in fpdf2), and so do ezdxf's documentation drawings.

parse_path() already rejects path data that does not start with a moveto, with its own error, so the check in svg_path_converter() was only reached for empty data, where first_is_move stays None. It now raises only when first_is_move is False, so an empty d gives the same empty path as a <path> without d.

Added test_path_empty_data ("" and whitespace) and test_path_not_starting_with_move, which checks that invalid path data still raises; the first fails on master. pytest test/svg test/drawing, black, pylint and mypy pass

@andersonhc
andersonhc merged commit c396b9b into py-pdf:master Nov 10, 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