Skip to content

fix: do not crash on UTF-8 BOM documents after jschardet 4 - #31

Merged
Kikobeats merged 2 commits into
masterfrom
cursor/critical-bug-management-718c
Oct 1, 2026
Merged

Kikobeats merged 2 commits into
masterfrom
cursor/critical-bug-management-718c

Conversation

@cursor

@cursor cursor Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

After the jschardet 4 bump, detect() reports chardet labels such as UTF-8-SIG for UTF-8 files that start with a BOM. iconv-lite does not recognize that name, so iconv.decode threw Encoding not recognized: 'UTF-8-SIG' whenever charset could not be read from the Content-Type header or a <meta> tag.

That is a common real-world input: Windows Notepad and many editors save UTF-8 with a BOM, and servers often send Content-Type: text/html with no charset.

Fix: map utf-8-sig to utf-8. Any other name iconv-lite does not implement is passed through, so iconv.decode throws instead of decoding those bytes as the target encoding.

Validation: existing fixtures still pass; added a test for BOM input without a charset hint, and a test that an unsupported charset= label throws.

Open in Web View Automation 

Note

Low Risk
Narrow encoding-alias fix in decode path; behavior for unsupported charsets remains fail-fast via iconv.

Overview
Fixes crashes when decoding UTF-8 with BOM HTML that has no charset in the Content-Type or document meta. jschardet 4 can report UTF-8-SIG, which iconv-lite does not accept, so iconv.decode used to throw on a common Windows/editor output pattern.

The change adds a small toIconvName helper and an utf-8-sig → utf-8 alias applied to both Content-Type–parsed and inferred encodings before decode. Other labels are still passed through unchanged, so unsupported declared charsets continue to fail at decode time rather than being silently mis-decoded.

Tests cover BOM-only detection (correct text, no leading BOM in output) and that an unknown charset= value throws with the encoding name in the error.

Reviewed by Cursor Bugbot for commit 15978f4. Bugbot is set up for automated code reviews on this repo. Configure here.

jschardet 4 reports chardet labels such as UTF-8-SIG that iconv-lite
does not recognize. Decoding then threw on common UTF-8-with-BOM input
when no charset was declared in headers or a meta tag.
@coderabbitai

coderabbitai Bot commented Oct 1, 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: 8f0b2d7c-2650-47c5-9c53-07f6cb5de776

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
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


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

coveralls commented Oct 1, 2026 •

Copy link
Copy Markdown

Coverage Status

Coverage is 88.0% — cursor/critical-bug-management-718c into master. No base build found for master.

A missing iconv codec was decoded as the target encoding, including
an explicit Content-Type charset. UTF-8-SIG still maps to utf-8.

Co-authored-by: Cursor <cursoragent@cursor.com>
@Kikobeats
Kikobeats marked this pull request as ready for review October 1, 2026 16:15
@Kikobeats
Kikobeats merged commit a5f8b65 into master Oct 1, 2026
4 checks passed
@Kikobeats
Kikobeats deleted the cursor/critical-bug-management-718c branch October 1, 2026 16:22
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