Skip to content

feat(iconv): code pages via encoding_rs (iconv_charsets feature) - #2941

Merged
chaliy merged 1 commit into
mainfrom
claude/project-thread-cs5tvz
Nov 18, 2026
Merged

chaliy merged 1 commit into
mainfrom
claude/project-thread-cs5tvz

Conversation

@chaliy

@chaliy chaliy commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Requested by Михайло · project thread

Part 2 of #2935, following #2937. Closes #2935.

What changed

  • iconv gains the WHATWG Encoding Standard charsets: windows-874 and windows-1250 to 1258, iso-8859-2 to 16, koi8-r/u, macintosh, ibm866, Shift_JIS, EUC-JP, ISO-2022-JP, GBK, GB18030, Big5 and EUC-KR. Common GNU spellings also work (latin9, cp936, cp932, eucjp, ...). iconv -l lists them.
  • They come from encoding_rs, behind a new iconv_charsets feature. It is on by default, listed by bashkit-cli and bashkit-capi, and absent from bashkit-wasm, the same way as tzdata. Without the feature, iconv refuses these charsets with exit 1.
  • The charsets that were already supported keep their own handling. WHATWG maps latin1, iso-8859-1 and ascii to windows-1252, so every windows-1252 label that is not spelled 1252 resolves to real Latin-1 or ASCII instead.
  • Errors keep exact byte positions, including in multibyte input. Characters the target cannot hold are errors, or are dropped under -c. They are never turned into &#NNN; HTML references.
  • A stateful target (ISO-2022-JP) is flushed back to ASCII at the end of the output.

Why

The main case in #2935: Excel exports in cp1252 or cp1250 (iconv -f cp1252 -t utf-8 export.csv → iconv: unsupported encoding 'cp1252').

Before / After

$ printf 'K\366ln \226 5\200\n' | iconv -f cp1252 -t utf-8
before: iconv: unsupported encoding 'cp1252'      after: Köln – 5€
$ printf 'Šč €\n' | iconv -f utf-8 -t windows-1250 | od -An -tx1
before: iconv: unsupported encoding 'windows-1250' after: 8a e8 20 80 0a

A new differential test checks the output bytes and exit codes against glibc iconv for cp1252 and cp1250 in both directions, iso-8859-15, GBK, and a Shift_JIS round trip.

Risk

  • Low. The dependency is new to bashkit's default build, but it was already in the lockfile (via markkit) with a safe-to-deploy exemption. Its license is (Apache-2.0 OR MIT) AND BSD-3-Clause, which is allowed.
  • The WHATWG tables differ from glibc's in a few corners. For example, windows-1252 decodes the 5 unassigned bytes to C1 controls instead of failing. This is recorded in L-ICONV-001.

Checklist

  • Tests added or updated: 10 new unit tests (multibyte round trips, malformed input positions, unmappable characters, latin1/ascii labels not treated as windows-1252, the replacement encoding refused, every byte through every charset with no panic), plus 1 differential integration test. The lib tests also pass with --no-default-features.
  • Backward compatibility considered. Knowledge updated: dependencies, browser package, limitations, threat model and log.

Adds windows-125x, iso-8859-x, koi8, macintosh and the CJK sets from the
WHATWG tables, behind a default-on `iconv_charsets` feature (absent from
the browser wasm package, like tzdata). Built-in names win; WHATWG labels
that alias latin1/ascii to windows-1252 resolve to the real charsets.
Errors keep exact byte positions; unmappable chars never become NCRs.

Closes #2935
@chaliy chaliy self-assigned this Nov 18, 2026
@chaliy
chaliy merged commit 75d6f65 into main Nov 18, 2026
67 checks passed
@chaliy
chaliy deleted the claude/project-thread-cs5tvz branch November 18, 2026 20:02
@chaliy chaliy mentioned this pull request Nov 19, 2026
2 tasks done
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.

Feature request: iconv code pages, raw byte output, -o and -c

1 participant