Skip to content

Fix xlsx: combine escaped UTF-16 surrogate pairs when decoding strings (#1025) - #1119

Merged
aiongg merged 1 commit into
storytold:mainfrom
MarekSpodBiedry:issue-1025
Oct 22, 2026
Merged

aiongg merged 1 commit into
storytold:mainfrom
MarekSpodBiedry:issue-1025

Conversation

@MarekSpodBiedry

Copy link
Copy Markdown
Contributor

Fixes #1025.

decode_xstring decoded each _xHHHH_ escape on its own through char::from_u32. UTF-16 surrogate units are not Unicode scalar values, so a supplementary character written as a pair of escapes (_xD83D__xDE00_ for U+1F600) stayed as literal escape text after import.

Now, when a high surrogate escape (D800-DBFF) is followed directly by a low surrogate escape (DC00-DFFF), the two are combined into one character.

  • Lone surrogates (a high one without a low one after it, or a low one alone) stay literal text, as before.
  • An escape protected with _x005F_ is still treated as literal text, so it never counts as the low half of a pair.
  • Shared strings, rich text runs, inline strings, comments, str cells and table column names all decode through decode_xstring, so this one change covers each of them.
  • encode_xstring is unchanged: it writes supplementary characters as they are, so the round trip already keeps them.

The new unit test xstring_surrogate_pairs checks upper- and lowercase pairs, lone high and low surrogates, a high surrogate followed by an escape that is not a low surrogate, and a protected escape. Without the fix, its first assertion fails.

@MarekSpodBiedry
MarekSpodBiedry marked this pull request as ready for review October 13, 2026 16:14
jesusthehelper-oss added a commit to jesusthehelper-oss/gridcraft that referenced this pull request Oct 19, 2026
@aiongg
aiongg merged commit 34de196 into storytold:main Oct 22, 2026
1 check 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.

fix(xlsx): xstring decoding does not combine escaped UTF-16 surrogate pairs

2 participants