Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 27 additions & 4 deletions src/bun_core/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2434,11 +2434,34 @@ pub(crate) mod strings_impl {
return false;
}
let b = self.bytes[i];
// TODO(port): full UTF-8 decode — bun_str owns the table-driven impl.
let (cp, w) = if b < 0x80 {
(b as i32, 1u8)
// Decode the WTF-8 sequence so multi-byte code points report their
// true width (Zig sets `width = cp_len`); fmt.rs collapses any
// `width > 1` code point to a single `_`. Invalid / truncated
// sequences fall back to a 1-byte step.
let seq = wtf8_byte_sequence_length(b) as usize;
let valid = (2..=4).contains(&seq)
&& i + seq <= self.bytes.len()
&& self.bytes[i + 1..i + seq]
.iter()
.all(|&c| (c & 0xC0) == 0x80);
let (cp, w): (i32, u8) = if !valid {
(b as i32, 1)
} else {
(b as i32, 1u8)
let cp = match seq {
2 => ((b as i32 & 0x1F) << 6) | (self.bytes[i + 1] as i32 & 0x3F),
3 => {
((b as i32 & 0x0F) << 12)
| ((self.bytes[i + 1] as i32 & 0x3F) << 6)
| (self.bytes[i + 2] as i32 & 0x3F)
}
_ => {
((b as i32 & 0x07) << 18)
| ((self.bytes[i + 1] as i32 & 0x3F) << 12)
| ((self.bytes[i + 2] as i32 & 0x3F) << 6)
| (self.bytes[i + 3] as i32 & 0x3F)
}
};
(cp, seq as u8)
};
cursor.i = i;
cursor.c = cp;
Expand Down
22 changes: 22 additions & 0 deletions test/bundler/bundler_naming.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,4 +302,26 @@ describe("bundler", () => {
},
],
});
// A non-ASCII basename char must collapse to a single "_" in the generated
// CommonJS wrapper symbol, not one "_" per UTF-8 byte. Regressed to
// `require_caf__utils` (the 2 bytes of "é" walked individually) because the
// identifier formatter resolved to a stub that never decoded multi-byte
// sequences (width always 1).
itBundled("naming/NonAsciiSourceFilenameSymbol", {
files: {
"/entry.js": /* js */ `
const u = require("./café-utils.js");
console.log(u.hi);
`,
"/café-utils.js": /* js */ `
module.exports = { hi: 1 };
`,
},
target: "bun",
onAfterBundle(api) {
api.expectFile("/out.js").toContain("require_caf_utils");
api.expectFile("/out.js").not.toContain("require_caf__utils");
},
run: { stdout: "1" },
});
});
Loading