fix: preserve non-BMP unicode characters (emojis) in double-quoted strings - #319
Open
david-hong-invitae wants to merge 1 commit into
Open
Conversation
david-hong-invitae
force-pushed
the
fix/unicode-emoji-preservation
branch
4 times, most recently
from
August 6, 2026 05:41
728b587 to
2cae265
Compare
…rings The ruyaml emitter (v0.91.0, latest on PyPI) escapes supplementary plane characters (U+10000-U+10FFFF, including all emojis) in double-quoted strings as \Uxxxxxxxx sequences because its allow_unicode range only covers up to U+FFFD. This is fixed on ruyaml's main branch but not yet released. Work around it by post-processing the emitter output to restore escaped non-BMP unicode sequences back to their original characters. Fixes lyz-code#300 Fixes lyz-code#227
david-hong-invitae
force-pushed
the
fix/unicode-emoji-preservation
branch
from
August 6, 2026 05:43
2cae265 to
ad2a051
Compare
Owner
|
Thank you for your contributions @david-hong-invitae , however, right now i'm unable to take care of the repository so i'm archiving it |
Owner
|
it looks that i can't archive it and let people interact in issues, so i'll leave it open and unmaintained: #272 |
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
Fixes #300, fixes #227 — non-BMP unicode characters (emojis) in double-quoted strings are replaced with
\Uxxxxxxxxescape sequences.Root cause: ruyaml's
Emitter.write_double_quoted(v0.91.0, latest on PyPI) only considers characters up to U+FFFD as "allowed unicode":This excludes the supplementary plane (U+10000–U+10FFFF) where emojis live, causing them to be escaped when inside double-quoted strings.
Note: This bug is already fixed on ruyaml's
mainbranch (pycontribs/ruyaml@d6a82e8), but was never released to PyPI — the latest available version is still 0.91.0 which has the bug. Until a new ruyaml release is published, yamlfix needs to work around it.Fix: Monkey-patch the emitter at module load to extend the allowed unicode range to include
'\U00010000' <= ch <= '\U0010FFFF'(supplementary planes). The patch is identical to what ruyaml's unreleasedmainbranch already has.Related issues
🔬→\U0001F52C)📈→\U0001F4C8)Test plan
test_fix_code_preserves_unicode_emojis_in_double_quoted_stringsé,ñ) still work correctlypreserve_quotesquote_basic_values=True+quote_representation='"'(issue Unexpected unicode escaping #227 repro)