Skip to content

fix: serialize None as null keyword in PDFArray - #1974

Merged
andersonhc merged 1 commit into
py-pdf:masterfrom
agustin18:fix/pdfarray-serialize-null
Sep 29, 2026
Merged

andersonhc merged 1 commit into
py-pdf:masterfrom
agustin18:fix/pdfarray-serialize-null

Conversation

@agustin18

Copy link
Copy Markdown

Description

Per ISO 32000-1 § 7.3.9 ("Null Object"):

The null object has a type and value that are almost never equal to any other object; there is only one object of this type, denoted by the keyword null.

While render_pdf_primitive in fpdf/syntax.py correctly converts None to "null", PDFArray.serialize() previously omitted None handling and fell back to Python's str(elem), producing invalid PDF tokens like [None] or [None None].

This PR adds explicit serialization of None as "null" in PDFArray.serialize(), handling both homogeneous arrays ([None, None] -> [null null]) and heterogeneous arrays ([1, None] -> [1\nnull]).

Tests

  • Added parameterized unit tests in test/test_syntax.py covering homogeneous null arrays, single-item null arrays, and heterogeneous arrays mixed with integers, booleans, and indirect objects (PDFObject).

Signed-off-by: agustin18 <agustinsaiz02@gmail.com>
@andersonhc
andersonhc merged commit 06408e8 into py-pdf:master Sep 29, 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