Skip to content

add_link/set_link: raise a clear error for a negative page - #2095

Merged
andersonhc merged 1 commit into
py-pdf:masterfrom
RavSinghChandan:link-negative-page
Nov 2, 2026
Merged

andersonhc merged 1 commit into
py-pdf:masterfrom
RavSinghChandan:link-negative-page

Conversation

@RavSinghChandan

Copy link
Copy Markdown

A negative page other than -1 (the current page) was stored as is, and the page reference was then taken from the end of the page list: in a 3-page document, add_link(page=-2) silently pointed to page 1. In a shorter document it failed at output() with a bare IndexError.

add_link() and set_link() (including named destinations) now raise ValueError: Invalid page number for a link: -2 - use -1 for the current page. A page of 0 (no page yet) is unchanged, as it is used by links set later with set_link().

  • 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 97c8932 into py-pdf:master Nov 2, 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