Skip to content

fix(pdf): specify UTF-8 when reading and writing form JSON - #1831

Open
TINGyu123644 wants to merge 1 commit into
anthropics:mainfrom
TINGyu123644:fix/pdf-form-json-utf8
Open

TINGyu123644 wants to merge 1 commit into
anthropics:mainfrom
TINGyu123644:fix/pdf-form-json-utf8

Conversation

@TINGyu123644

Copy link
Copy Markdown

Summary

The PDF form pipeline exchanges fields.json between stages. Three scripts touch that file without an explicit encoding:

  • extract_form_structure.py writes it with open(..., "w")
  • create_validation_image.py and fill_pdf_form_with_annotations.py read it with open(..., "r")

On a Windows cp1252 locale:

  • the write crashes with UnicodeEncodeError: 'charmap' codec can't encode character as soon as a field label or value contains a non-ASCII character (very common with real forms, e.g. non-ASCII labels);
  • reading a fields.json produced on another platform (where UTF-8 is the default) fails to decode or silently mis-decodes.

This PR pins encoding="utf-8" on all four calls, making the form pipeline locale-independent. Behavior on UTF-8 locales is unchanged.

Note: extract_form_field_info.py was already covered by #1602; this PR covers the remaining form-JSON readers/writers.

How it was tested

  • All three files parse (AST).
  • The change is confined to the file-open calls; the JSON content produced/consumed by the pipeline is UTF-8 in practice.

The PDF form scripts exchange fields.json between stages. extract_form_structure.py
writes it with open(..., 'w') and create_validation_image.py / fill_pdf_form_with_annotations.py
read it with open(..., 'r'), all without an explicit encoding. On a Windows
cp1252 locale the write crashes with UnicodeEncodeError as soon as a field label
or value contains a non-ASCII character, and reading a UTF-8 fields.json
produced on another platform fails to decode. Pin encoding='utf-8' on all four
calls so the form pipeline is locale-independent.
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.

1 participant