Skip to content

fix(convert): decode JIS X 0212 0x2237 to a single character - #69

Merged
polygonplanet merged 1 commit into
polygonplanet:masterfrom
youdie006:jisx0212-ascii-single-byte
Oct 2, 2026
Merged

polygonplanet merged 1 commit into
polygonplanet:masterfrom
youdie006:jisx0212-ascii-single-byte

Conversation

@youdie006

Copy link
Copy Markdown
Contributor

EUCJPToUTF8() and JISToUTF8() always write at least two bytes for a JIS X 0212 table value. 0x2237 is the one entry that maps to ASCII (~), so EUC-JP 8F A2 B7 decodes to a NUL followed by ~:

Encoding.convert([0x8f, 0xa2, 0xb7], { to: 'UNICODE', from: 'EUCJP' }) // [0, 126]

The ISO-2022-JP form (ESC $ ( D + 22 37) does the same. glibc iconv -t EUC-JP writes ~ (as in 10時~12時) as these bytes, so the NUL shows up in real text. Python's euc_jp decodes them to ~, and glibc iconv and WHATWG TextDecoder to ~; all return one character.

This writes values below 0x80 as one byte. Converting every EUC-JP, JIS and SJIS code to each target, only the six outputs for 0x2237 to UTF8, UNICODE and UTF16 change. Added a test; npm test and npm run lint pass.

Written with AI assistance (Claude); I have reviewed the change.

EUCJPToUTF8() and JISToUTF8() always wrote at least two bytes for a JIS
X 0212 table value, so 0x2237, which maps to ~, decoded to a NUL
followed by ~.
@polygonplanet

polygonplanet commented Oct 2, 2026 •

Copy link
Copy Markdown
Owner

@youdie006
Thank you for the detailed PR!
I confirmed that an extra NUL (0x00) was inserted in both JIS (ISO-2022-JP) and EUC-JP using the example code you provided. I also appreciate that the fix is minimal and focused.
This looks good to me, so I will go ahead and merge this. Thank you!

@polygonplanet
polygonplanet merged commit 714c968 into polygonplanet:master Oct 2, 2026
9 checks passed
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.

2 participants