Repository navigation
fix: fall back when inferred encoding is unknown to iconv - #32
Merged
Merged
Conversation
jschardet 4 can report codec names iconv-lite does not implement (ISO-2022-JP, low-confidence cp500, …). Passing those through to iconv.decode crashes HTML pipelines that have no charset hint. Skip unsupported inferred names so getEncoding uses the target encoding. Declared unknown charsets still throw.
|
Important Review skippedBot user detected. To trigger a single review, invoke the ⚙️ Run configuration
You can disable this status message by setting the Use the checkbox below for a quick retry:
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. Comment |
Kikobeats
marked this pull request as ready for review
October 14, 2026 07:37
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
After the jschardet 4 bump,
detect()can report codec names iconv-lite does not implement. The utf-8-sig alias in #31 covers BOM UTF-8, but other labels still reachiconv.decodeand throw.Concrete triggers with no
charsetin Content-Type or<meta>:ISO-2022-JPat 0.95 confidence; iconv-lite has no such codec →Encoding not recognized.cp500at very low confidence; iconv-lite also lacks that codec → same crash.Fix: only use an inferred encoding when iconv-lite actually implements it. Otherwise fall back to the caller’s target encoding (the same path as “detection returned nothing”). An explicit unknown
charset=still throws, matching the existing test.Validation: existing fixtures still pass; added tests for ISO-2022-JP ESC sequences and a jschardet
cp500guess.Note
Low Risk
Decode-path hardening only; wrong-encoding fallback on bad inference is possible but replaces a hard throw and does not change explicit charset error behavior.
Overview
Prevents crashes when jschardet 4 infers a codec that iconv-lite does not support (e.g.
ISO-2022-JP,cp500) and there is no usablecharsethint.inferredEncodingnow maps labels through the existing alias helper and only returns a guess wheniconv.encodingExistsis true; otherwise encoding selection skips inference and uses the caller’s target encoding (same as “no detection”). Explicitcharset=values that iconv cannot handle still throw, unchanged.Adds tests for ISO-2022-JP escape-sequence HTML and for jschardet guessing an unsupported label on EUC-JP content.
Reviewed by Cursor Bugbot for commit 7fd83e5. Bugbot is set up for automated code reviews on this repo. Configure here.