Skip to content

fix: fall back when inferred encoding is unknown to iconv - #32

Merged
Kikobeats merged 1 commit into
masterfrom
cursor/critical-bug-management-7257
Oct 14, 2026
Merged

Kikobeats merged 1 commit into
masterfrom
cursor/critical-bug-management-7257

Conversation

@cursor

@cursor cursor Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

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 reach iconv.decode and throw.

Concrete triggers with no charset in Content-Type or <meta>:

  • ISO-2022-JP HTML (escape sequences). jschardet reports ISO-2022-JP at 0.95 confidence; iconv-lite has no such codec → Encoding not recognized.
  • Short EUC-JP / Big5 pages. jschardet 4 often labels these cp500 at 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 cp500 guess.

Open in Web View Automation 

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 usable charset hint.

inferredEncoding now maps labels through the existing alias helper and only returns a guess when iconv.encodingExists is true; otherwise encoding selection skips inference and uses the caller’s target encoding (same as “no detection”). Explicit charset= 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.

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.
@coderabbitai

coderabbitai Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 5f9b3f46-8563-4cd9-8495-f0f5e2b28c3b

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage is 92.593% — cursor/critical-bug-management-7257 into master. No base build found for master.

@Kikobeats
Kikobeats marked this pull request as ready for review October 14, 2026 07:37
@Kikobeats
Kikobeats merged commit dbf2733 into master Oct 14, 2026
4 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.

3 participants