Skip to content

Encode lone surrogates as U+FFFD - #307

Open
draarivpatel-ui wants to merge 1 commit into
msgpack:mainfrom
draarivpatel-ui:fix-lone-surrogate-encoding
Open

draarivpatel-ui wants to merge 1 commit into
msgpack:mainfrom
draarivpatel-ui:fix-lone-surrogate-encoding

Conversation

@draarivpatel-ui

Copy link
Copy Markdown

Summary

Fixes #303.

  • Replace lone UTF-16 surrogates with U+FFFD in the short-string JavaScript encoder.
  • Match TextEncoder, which is already used for longer strings, so output no longer depends on string length.
  • Add regression coverage for lone high surrogates, lone low surrogates, reversed surrogates, and valid surrogate pairs.

Verification

  • The new lone-surrogate test fails before the fix with ED A0 80 and passes after it with EF BF BD.
  • npm run lint passes.
  • npm test passes: 329 passing.
  • npm run prepare passes.

Copilot AI balanced review requested due to automatic review settings November 26, 2026 01:30

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

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.

encode() writes a lone UTF-16 surrogate as invalid UTF-8 in a string of 50 characters or fewer

2 participants