Skip to content

Handle UTF-16 surrogate pairs in encoding - #168

Open
Neighbor-Z wants to merge 1 commit into
hanwen:masterfrom
Neighbor-Z:upstream
Open

Neighbor-Z wants to merge 1 commit into
hanwen:masterfrom
Neighbor-Z:upstream

Conversation

@Neighbor-Z

Copy link
Copy Markdown

Add proper handling of UTF-16 surrogate pairs in mtp/encoding.go. decodeStr now recognizes high/low surrogates and combines them into runes (avoids producing broken emoji and other >U+FFFF chars) and guards against trimming when no bytes were written. encodeStr encodes runes above the BMP as UTF-16 surrogate pairs and correctly counts code units. encodeStrField allocates a larger buffer to accommodate worst-case surrogate expansion. These changes fix incorrect encoding/decoding of characters outside the BMP issue.

Add proper handling of UTF-16 surrogate pairs in mtp/encoding.go. decodeStr now recognizes high/low surrogates and combines them into runes (avoids producing broken emoji and other >U+FFFF chars) and guards against trimming when no bytes were written. encodeStr encodes runes above the BMP as UTF-16 surrogate pairs and correctly counts code units. encodeStrField allocates a larger buffer to accommodate worst-case surrogate expansion. These changes fix incorrect encoding/decoding of characters outside the BMP issue.
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