Skip to content

fix: escape non-BMP noncharacters as surrogate pairs in escapeUnicode - #2726

Open
1AbdullahButt wants to merge 5 commits into
wxt-dev:mainfrom
1AbdullahButt:fix/escape-unicode-supplementary
Open

1AbdullahButt wants to merge 5 commits into
wxt-dev:mainfrom
1AbdullahButt:fix/escape-unicode-supplementary

Conversation

@1AbdullahButt

@1AbdullahButt 1AbdullahButt commented Nov 6, 2026 •

Copy link
Copy Markdown

Overview

escapeUnicode was writing noncharacters above U+FFFF as 5-6 digit escapes like \u1ffff. JavaScript only reads 4 hex digits after \u, so that gets parsed as a different character followed by a stray f.

Now those characters are written as a surrogate pair of two 4-digit escapes (e.g. \ud83f\udfff), which is the correct way to write them in JS. Output for normal BMP characters is unchanged.

I also added a test file with 4 tests. 2 of them fail without the fix, and all 4 pass with it. After review, the tests use JSON.parse instead of new Function, and I removed the extra quotes. A maintainer also added a commit that disables the no-control-regex lint rule for the test file.

Manual Testing

Ran the new tests with bunx vitest. All 4 pass with the fix, and 2 of 4 fail without it. The formatting check passes too.

Related Issue

Closes #2725

I used Claude Code to help write the code. I reviewed it.

@coderabbitai

coderabbitai Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The change exports escapeNonCharacterUnicode and formats matched non-characters as separate four-digit UTF-16 code-unit escapes. Tests cover BMP and supplementary-plane non-characters, output character encoding, value preservation, and unchanged input without non-characters.

Changes: Unicode non-character escaping

Layer / File(s) Summary
Escaping and output validation
packages/wxt/src/internal/builtin-modules/escape-unicode.ts, packages/wxt/src/internal/builtin-modules/__tests__/escape-unicode.test.ts
escapeNonCharacterUnicode is exported and emits a four-digit escape for each UTF-16 code unit of a matched non-character. Tests check BMP and supplementary-plane cases, ASCII-only JSON output, value preservation, and unchanged input without non-characters.

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: Minimal · up to 0451a

This fix makes escaping of supplementary-plane noncharacters preserve their values, and BMP output is unchanged. No merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title clearly identifies the main change: escaping non-BMP noncharacters as UTF-16 surrogate pairs in escapeUnicode.
Linked Issues check Passed Issue #2725 requires preserving supplementary-plane noncharacters and adding a unit test. escapeNonCharacterUnicode now escapes each UTF-16 code unit with a four-digit \\u escape, which produces su…
Out of Scope Changes check Passed The diff stays within issue #2725. The function export enables direct unit testing, and the documentation describes the implemented surrogate-pair behavior. The added test coverage supports the fix.
Description check Passed The description covers the Overview, Manual Testing, and Related Issue sections of the template. The Overview explains the bug: noncharacters above U+FFFF are written as 5-6 digit \u escapes, which Ja…
Full details: Linked Issues check

Explanation

Issue #2725 requires preserving supplementary-plane noncharacters and adding a unit test. escapeNonCharacterUnicode now escapes each UTF-16 code unit with a four-digit \u escape, which produces surrogate pairs such as \ud83f\udfff. The new tests cover BMP values, supplementary-plane values, ASCII output, evaluation to the original string, and unchanged other characters.

Full details: Description check

Explanation

The description covers the Overview, Manual Testing, and Related Issue sections of the template. The Overview explains the bug: noncharacters above U+FFFF are written as 5-6 digit \u escapes, which JavaScript reads as four hex digits plus literal text. It states the fix: such characters are now written as a surrogate pair of two 4-digit escapes, and BMP output is unchanged. The Manual Testing section names the command run (bunx vitest), the results (4 of 4 pass with the fix, 2 of 4 fail without it), and a passing formatting check. The Related Issue section links #2725. The description does not use the exact template wording for the issue closing line ("This PR closes #..."), but it does link the issue with a clear closing reference. The description notes the test changes made after review and a lint-rule change in the test file. The description does not state that the test was run with Bun; it says bunx, which is the same tool family, so the test command is clear enough to reproduce. Overall the description is mostly complete and matches the template.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 67be7e62-39f6-404b-9188-9c2d6e081b13
Commits

Reviewing files that changed from the base of the PR and between abfdd7f and 0451ae6.

Files selected for processing: 2

  • packages/wxt/src/internal/builtin-modules/__tests__/escape-unicode.test.ts
  • packages/wxt/src/internal/builtin-modules/escape-unicode.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@netlify

netlify Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for creative-fairy-df92c4 ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit df4a687
🔍 Latest deploy log https://app.netlify.com/projects/creative-fairy-df92c4/deploys/6b0ab979cc5886b018daad42
😎 Deploy Preview https://deploy-preview-2726--creative-fairy-df92c4.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@github-actions github-actions Bot added the pkg/wxt Includes changes to the `packages/wxt` directory label Nov 6, 2026
@nishu-murmu

Copy link
Copy Markdown
Collaborator

Please summarize the PR description!

@1AbdullahButt

Copy link
Copy Markdown
Author

Shortened the description, thanks.

@aklinker1 aklinker1 changed the title fix(wxt): escape non-BMP noncharacters as surrogate pairs in escapeUnicode fix: escape non-BMP noncharacters as surrogate pairs in escapeUnicode Nov 10, 2026
@pkg-pr-new

pkg-pr-new Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@wxt-dev/analytics

npm i https://pkg.pr.new/@wxt-dev/analytics@2726

@wxt-dev/auto-icons

npm i https://pkg.pr.new/@wxt-dev/auto-icons@2726

@wxt-dev/browser

npm i https://pkg.pr.new/@wxt-dev/browser@2726

@wxt-dev/i18n

npm i https://pkg.pr.new/@wxt-dev/i18n@2726

@wxt-dev/is-background

npm i https://pkg.pr.new/@wxt-dev/is-background@2726

@wxt-dev/module-react

npm i https://pkg.pr.new/@wxt-dev/module-react@2726

@wxt-dev/module-solid

npm i https://pkg.pr.new/@wxt-dev/module-solid@2726

@wxt-dev/module-svelte

npm i https://pkg.pr.new/@wxt-dev/module-svelte@2726

@wxt-dev/module-vue

npm i https://pkg.pr.new/@wxt-dev/module-vue@2726

@wxt-dev/runner

npm i https://pkg.pr.new/@wxt-dev/runner@2726

@wxt-dev/storage

npm i https://pkg.pr.new/@wxt-dev/storage@2726

@wxt-dev/unocss

npm i https://pkg.pr.new/@wxt-dev/unocss@2726

@wxt-dev/webextension-polyfill

npm i https://pkg.pr.new/@wxt-dev/webextension-polyfill@2726

wxt

npm i https://pkg.pr.new/wxt@2726

commit: df4a687

@codecov

codecov Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.26%. Comparing base (a71b426) to head (854ec23).
⚠️ Report is 26 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2726      +/-   ##
==========================================
- Coverage   80.35%   80.26%   -0.10%     
==========================================
  Files         140      140              
  Lines        4175     4176       +1     
  Branches      968      968              
==========================================
- Hits         3355     3352       -3     
- Misses        720      725       +5     
+ Partials      100       99       -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@aklinker1 aklinker1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the PR, two small changes.

@aklinker1

Copy link
Copy Markdown
Member

Looks like checks are also failing:

⚠ Unexpected control character (eslint(no-control-regex))
  → ./src/internal/builtin-modules/__tests__/escape-unicode.test.ts:21:32

You can disable the rule for that file.

@1AbdullahButt

Copy link
Copy Markdown
Author

Thanks, switched the tests to JSON.parse, dropped the extra quotes, and disabled no-control-regex for that test file. Checks are green now.

@suveshmoza

Copy link
Copy Markdown
Collaborator

@1AbdullahButt Formatting check(oxfmt) is failing, run ./node_modules/.bin/oxfmt . from repo root and push changes

1AbdullahButt and others added 2 commits November 27, 2026 00:19
…icode

`experimental.escapeUnicode` wrote code points above U+FFFF as a single
`\u` escape with 5-6 hex digits (e.g. `\u1ffff`), which JavaScript reads
as U+1FFF followed by a literal digit. Escape each UTF-16 code unit
instead so these characters become valid surrogate-pair escapes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@suveshmoza

Copy link
Copy Markdown
Collaborator

Thanks, switched the tests to JSON.parse, dropped the extra quotes, and disabled no-control-regex for that test file. Checks are green now.

@1AbdullahButt You sure? Extra quotes and new Function are still there

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@1AbdullahButt

Copy link
Copy Markdown
Author

You're right, sorry about that. When I rebased onto main on the 26th, I used a local branch that didn't have those changes, so the force-push dropped them. They're back in d6a2db6 now: the first two tests have no extra quotes, and the round-trip test uses JSON.parse instead of new Function. I kept your no-control-regex disable commit on top.

vitest run escape-unicode.test.ts passes 4/4, and oxfmt --check is clean on the file.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg/wxt Includes changes to the `packages/wxt` directory

Projects

None yet

Development

Successfully merging this pull request may close these issues.

experimental.escapeUnicode writes invalid escapes for noncharacters above U+FFFF

4 participants