Repository navigation
Conversation
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.
Details
This PR fixes
@plasmohq/parcel-compressor-utf8dropping 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
transformSegmentsplit the segment by code point (Array.from) and then escaped onlycharCodeAt(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.StringDecoderalready keeps multi-byte UTF-8 sequences whole across stream chunks, so nothing else needed to change."🚀""\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 onmain.Known limitations
const 𠮷 = 1) still becomes invalid JavaScript after escaping, before and after this change. That is outside this fix.Code of Conduct
Contacts
If your PR is accepted, we will award you with the
Contributorrole on Discord server.To join the server, visit: https://www.plasmo.com/s/d