Skip to content

SVG: read a NaN or infinite gradient coordinate as 0, like an invalid one - #2118

Merged
andersonhc merged 2 commits into
py-pdf:masterfrom
RavSinghChandan:svg-gradient-coordinate-finite
Nov 7, 2026
Merged

andersonhc merged 2 commits into
py-pdf:masterfrom
RavSinghChandan:svg-gradient-coordinate-finite

Conversation

@RavSinghChandan

Copy link
Copy Markdown

A gradient coordinate that can not be parsed, such as x1="bad", is read as 0 with a warning. But float() accepts nan and inf, so <linearGradient x1="nan"> wrote /Coords [nan 0 1 0] into the PDF, and <radialGradient r="nan"> a NaN radius, neither a valid PDF number.

A NaN or infinite coordinate (also as a percentage, -inf%) is now handled like any other invalid one: a warning, and 0. For r, that means the existing "invalid radius, skipping" path.

Test added: the gradient renders exactly like one with a coordinate of 0, for both gradient types (the NaN and infinite cases fail on master).

  • A unit test is covering the code added / modified by this PR
  • A mention of the change is present in CHANGELOG.md
  • This PR is ready to be merged

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