Skip to content

Encode JIS X 0212 characters with the standard 3-byte form - #63

Open
gaoflow wants to merge 1 commit into
polygonplanet:masterfrom
gaoflow:fix-jisx0212-standard-encoding
Open

Encode JIS X 0212 characters with the standard 3-byte form#63
gaoflow wants to merge 1 commit into
polygonplanet:masterfrom
gaoflow:fix-jisx0212-standard-encoding

Conversation

@gaoflow

@gaoflow gaoflow commented Jul 29, 2026

Copy link
Copy Markdown

The EUC-JP and ISO-2022-JP encoders emit 280 JIS X 0212 characters in a non-standard 2-byte form that no standard decoder accepts. These code points are duplicated into UTF8_TO_JIS_TABLE at rows unassigned by JIS X 0208, and that table is checked before UTF8_TO_JISX0212_TABLE, so the existing 3-byte path (encoding-convert.js:718) is never reached.

For example U+4E28 encodes to [0xF9,0xAD], which Python's euc_jp rejects, whereas the library's own decoder and the changelog's "Supports JIS X 0212:1990" expect [0x8F,0xB0,0xA9]:

Encoding.convert([0x4E28], 'EUCJP', 'UNICODE') // [249,173], not [143,176,169]

When a code point is present in both tables it now uses the JIS X 0212 form. The 280 affected characters occupy JIS X 0208 rows 13 and 89-92, which are all unassigned, so no genuine JIS X 0208 character is rerouted and Shift_JIS output is unchanged. Verified against Python euc_jp/iso2022_jp_2: all 280 now round-trip; npm test passes (178).

The EUC-JP and ISO-2022-JP encoders consulted UTF8_TO_JIS_TABLE before
UTF8_TO_JISX0212_TABLE. 280 JIS X 0212 code points are also duplicated in
UTF8_TO_JIS_TABLE at rows unassigned by JIS X 0208, so they were emitted as
a 2-byte code in those rows rather than the JIS X 0212 form, producing output
that standard EUC-JP and ISO-2022-JP decoders reject.

Fall through to the JIS X 0212 form (EUC-JP SS3 0x8F / ISO-2022-JP ESC $ ( D)
whenever a code point is present in both tables.
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.

1 participant