Skip to content

lib: implement WHATWG-spec Big5 decoder in js - #65458

Open
agape1225 wants to merge 1 commit into
nodejs:mainfrom
agape1225:lib-encoding-big5-whatwg-decoder
Open

lib: implement WHATWG-spec Big5 decoder in js#65458
agape1225 wants to merge 1 commit into
nodejs:mainfrom
agape1225:lib-encoding-big5-whatwg-decoder

Conversation

@agape1225

Copy link
Copy Markdown
Contributor

TextDecoder('big5') was routed through ICU's Big5 converter, whose table includes vendor/PUA mappings the WHATWG Encoding Standard does not define. Byte sequences the standard defines as invalid (and which must decode to U+FFFD, or throw when fatal) instead decoded to those extra ICU-only characters, e.g. bytes 0x83 0x5C decoded to U+F00E instead of U+FFFD U+005C, even with fatal: true.

This adds a small, self-contained decoder for the 'big5' label (and its aliases, which the standard maps to the same decoder) that implements the algorithm and index table from the Encoding Standard directly, mirroring how single-byte.js already reimplements the legacy single-byte encodings instead of relying on ICU for them. It does not touch the ICU-backed path used by any other encoding.

Refs: https://encoding.spec.whatwg.org/#big5-decoder
Refs: #61041
Fixes: #40091

@nodejs-github-bot nodejs-github-bot added encoding Issues and PRs related to the TextEncoder and TextDecoder APIs. needs-ci PRs that need a full CI run. labels Aug 21, 2026
@codecov

codecov Bot commented Aug 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.05%. Comparing base (f7968e7) to head (6e20b75).
⚠️ Report is 279 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #65458      +/-   ##
==========================================
- Coverage   90.12%   90.05%   -0.08%     
==========================================
  Files         752      770      +18     
  Lines      252315   261455    +9140     
  Branches    47438    49665    +2227     
==========================================
+ Hits       227411   235444    +8033     
- Misses      16212    17050     +838     
- Partials     8692     8961     +269     
Files with missing lines Coverage Δ
lib/internal/encoding.js 96.75% <100.00%> (+0.09%) ⬆️
lib/internal/encoding/big5.js 96.55% <ø> (ø)

... and 207 files with indirect coverage changes

🚀 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.

TextDecoder('big5') was routed through ICU's Big5 converter, whose
table includes vendor/PUA mappings the WHATWG Encoding Standard does
not define. Byte sequences the standard defines as invalid (and
which must decode to U+FFFD, or throw when fatal) instead decoded to
those extra ICU-only characters, e.g. bytes 0x83 0x5C decoded to
U+F00E instead of U+FFFD U+005C, even with `fatal: true`.

This adds a small, self-contained decoder for the 'big5' label (and
its aliases, which the standard maps to the same decoder) that
implements the algorithm and index table from the Encoding Standard
directly, mirroring how single-byte.js already reimplements the
legacy single-byte encodings instead of relying on ICU for them. It
does not touch the ICU-backed path used by any other encoding.

The decoder module is required lazily from internal/encoding.js, only
when a Big5 TextDecoder is constructed, so its large base64 index
table is not pulled into the startup snapshot; internal/encoding.js
itself is loaded during bootstrap.

Refs: https://encoding.spec.whatwg.org/#big5-decoder
Refs: nodejs#61041
Fixes: nodejs#40091
Signed-off-by: agape1225 <[email protected]>
@agape1225
agape1225 force-pushed the lib-encoding-big5-whatwg-decoder branch from b777d0a to 6e20b75 Compare September 4, 2026 06:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

encoding Issues and PRs related to the TextEncoder and TextDecoder APIs. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TextDecoder does not error incorrectly for legacy byte sequences

2 participants