Repository navigation
fix(pdf): specify UTF-8 when reading and writing form JSON - #1831
Open
TINGyu123644 wants to merge 1 commit into
Open
TINGyu123644 wants to merge 1 commit into
TINGyu123644 wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The PDF form pipeline exchanges
fields.jsonbetween stages. Three scripts touch that file without an explicit encoding:extract_form_structure.pywrites it withopen(..., "w")create_validation_image.pyandfill_pdf_form_with_annotations.pyread it withopen(..., "r")On a Windows cp1252 locale:
UnicodeEncodeError: 'charmap' codec can't encode characteras soon as a field label or value contains a non-ASCII character (very common with real forms, e.g. non-ASCII labels);fields.jsonproduced 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.pywas already covered by #1602; this PR covers the remaining form-JSON readers/writers.How it was tested