Skip to content

Decode UTF-8 text from binary-mode streams in the Python loader - #461

Open
illusionoftalha wants to merge 1 commit into
amazon-ion:masterfrom
illusionoftalha:fix/decode-utf8-text-streams
Open

illusionoftalha wants to merge 1 commit into
amazon-ion:masterfrom
illusionoftalha:fix/decode-utf8-text-streams

Conversation

@illusionoftalha

Copy link
Copy Markdown

Issue #, if available:

Fixes #115.

Description of changes:

The pure-Python loader feeds text from a binary-mode stream to the byte-oriented text reader. Literal UTF-8 bytes are consequently interpreted as separate code points, corrupting symbols, strings, field names and annotations.

After the existing Ion binary-marker detection identifies text, wrap that stream in an incremental UTF-8 reader and select the Unicode text parser. The wrapper leaves ownership of the underlying stream with the caller. Ion binary data continues through the existing binary reader.

Add ten regression cases covering quoted symbols, short and long strings, struct field names and annotations, with both eager and iterative parsing. A catalog explicitly selects the pure-Python path even when the C extension is installed.

Validation on Windows / Python 3.12:

  • All ten regression cases failed before the source fix and pass afterward.
  • PYTHONPATH=src-python python -m pytest tests --ignore=tests/test_benchmark_cli.py --ignore=tests/test_benchmark_spec.py -q: 29,220 passed, 5 skipped. Test vectors were initialized from the pinned submodule revision.
  • The five skips require the C extension, which was not built locally. Benchmark tests were excluded as in the project's CI command.
  • git diff --check passes.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

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.

Reading a literal (non-escaped) emoji doesn't work when reading from a file with mode 'rb'

1 participant