Skip to content

fix: preserve surrogate pairs in Parcel UTF-8 output - #1365

Open
akysil wants to merge 1 commit into
PlasmoHQ:mainfrom
akysil:fix/1360-plasmohq-parcel-compressor-utf8-drops-lo
Open

akysil wants to merge 1 commit into
PlasmoHQ:mainfrom
akysil:fix/1360-plasmohq-parcel-compressor-utf8-drops-lo

Conversation

@akysil

@akysil akysil commented Nov 29, 2026

Copy link
Copy Markdown

Details

This PR fixes @plasmohq/parcel-compressor-utf8 dropping the low surrogate of characters outside the BMP (emoji, supplementary CJK, math symbols). Before, the low surrogate was lost whenever both halves of a surrogate pair fell within the same 1024-unit segment. A bundle containing "🚀" was emitted as "\ud83d", a lone high surrogate.

Fixes #1360

Approach

transformSegment split the segment by code point (Array.from) and then escaped only charCodeAt(0) of each one. It now splits by UTF-16 code unit (split("")), so each half of a pair is escaped on its own. That gives the same output whether or not a pair straddles the 1024-unit segment boundary. StringDecoder already keeps multi-byte UTF-8 sequences whole across stream chunks, so nothing else needed to change.

Input Before After
"🚀" "\ud83d" "\ud83d\ude80"
"𠮷" "\ud842" "\ud842\udfb7"
"𝕏" "\ud835" "\ud835\udd4f"

Tested by piping buffers through Utf8Transform: the issue's examples, surrogate pairs at offsets 1021-1024 around the segment boundary, a 4-byte character split across stream chunks, and a round trip. All pass with the change; 9 of the 12 cases fail on main.

Known limitations

  • A supplementary character used as an identifier (e.g. const 𠮷 = 1) still becomes invalid JavaScript after escaping, before and after this change. That is outside this fix.

Code of Conduct

  • I agree to follow this project's Code of Conduct
  • I agree to license this contribution under the MIT LICENSE
  • I checked the current PR for duplication.

Contacts

  • (OPTIONAL) Discord ID: b81234901824

If your PR is accepted, we will award you with the Contributor role on Discord server.

To join the server, visit: https://www.plasmo.com/s/d

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.

@plasmohq/parcel-compressor-utf8 drops low surrogates and corrupts emojis / non-BMP characters

1 participant