AI News HubLIVE
In-site rewrite2 min read

Robobun Fixes Bun Module Loader UTF-8 Encoding Bug

PR #33864 fixes a bug in Bun's module loader where UTF-8 bytes in banner/footer were misinterpreted as Latin-1 under --target=bun, causing mojibake and syntax errors. The fix switches string construction to UTF-8 decoding with ASCII fast-path, and also synchronizes bytecode cache key generation.

SourceHacker News AIAuthor: struanr

Uh oh!

There was an error while loading. Please reload this page.

Notifications You must be signed in to change notification settings

Fork 4.9k

Star 93.9k

Conversation

Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy Markdown

Collaborator

-->

module loader: decode // @Bun source as UTF-8, not Latin-1

c1197bc

bun build --target=bun emits a // @Bun pragma that tells the module loader to hand the file to JSC verbatim. The two already_bundled paths built the WTF::String from the raw file bytes via String::clone_latin1, which treats each byte as one Latin-1 code unit. The printer's ASCII-only escaping covers program text, but --banner/--footer are appended as raw bytes, so a non-ASCII banner put UTF-8 bytes into a file the loader then reinterpreted as Latin-1: string literals came back mojibake and non-ASCII identifiers became a SyntaxError.

Switch both sites to String::clone_utf8, which fast-paths through simdutf to the same Latin-1 memcpy when the input is all-ASCII (the common case) and UTF-8 decodes otherwise.

Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy Markdown

Contributor

-->

github-actions Bot

added the

claude

label

Jul 9, 2026

Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy Markdown

Collaborator

Author

❌ @robobun, your commit 19c519b has 5 failures in Build #71145 (All Failures):

test/js/web/websocket/autobahn.test.ts - code 1 on 🍎 14 aarch64

test/js/bun/webview/webview.test.ts - code 1 on 🍎 14 aarch64

test/js/bun/http/proxy-stress-concurrent.test.ts - code 1 on 🍎 14 x64

test/regression/issue/26030.test.ts - code 1 on 🐧 3.23 x64

test/js/node/test/parallel/test-worker-message-port-transfer-terminate.js - SIGABRT on 🐧 13 x64-asan

🧪   To try this PR locally:

bunx bun-pr 33864

That installs a local version of the PR into your bun-33864 executable, so you can run:

bun-33864 --bun

-->

claude Bot

reviewed

Jul 9, 2026

View reviewed changes

Copy Markdown

Contributor

-->

Uh oh!

There was an error while loading. Please reload this page.

bytecode: build the SourceCodeKey from UTF-8 to match the loader

68c1594

The previous commit made the already_bundled loader sites decode source.contents as UTF-8. generateCached{Module,CommonJSProgram}ByteCodeFromSourceCode still built the WTF::String via the Latin-1 span constructor, so a non-ASCII banner/footer under --target=bun --bytecode produced a .jsc whose serialized SourceCodeKey was derived from the mojibake string while the loader computed its key from the UTF-8 string. decodeCodeBlock rejected the mismatch and JSC silently re-parsed, leaving the sidecar as dead weight.

Route both through a helper that mirrors BunString__fromBytes: simdutf validate_ascii fast-paths to the Latin-1 constructor, else decodes UTF-8.

claude Bot

reviewed

Jul 9, 2026

View reviewed changes

Copy Markdown

Contributor

-->

ci: retrigger

19c519b

claude Bot

reviewed

Jul 9, 2026

View reviewed changes

Copy Markdown

Contributor

-->

Copy Markdown

Collaborator

Author

-->

Jarred-Sumner

added the

slop

label

Jul 9, 2026

Copy Markdown

Contributor

-->

github-actions Bot

changed the title module loader: decode // @bun source as UTF-8, not Latin-1

ai slop

Jul 9, 2026

github-actions Bot

closed this

Jul 9, 2026

-->

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

Show hidden characters

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.

Robobun Fixes Bun Module Loader UTF-8 Encoding Bug | AI News Hub