mirror of
https://github.com/oven-sh/bun
synced 2026-02-16 05:42:43 +00:00
fix(windows): handle invalid utf16le in command line arguments (#11612)
This commit is contained in:
@@ -48,20 +48,29 @@ pub fn count16(this: *StringBuilder, slice: []const u16) void {
|
||||
}
|
||||
|
||||
pub fn count16Z(this: *StringBuilder, slice: [:0]const u16) void {
|
||||
const result = bun.simdutf.length.utf8.from.utf16.le(slice);
|
||||
const result = bun.strings.elementLengthUTF16IntoUTF8([:0]const u16, slice);
|
||||
this.cap += result + 1;
|
||||
}
|
||||
|
||||
pub fn append16(this: *StringBuilder, slice: []const u16) ?[:0]u8 {
|
||||
pub fn append16(this: *StringBuilder, slice: []const u16, fallback_allocator: std.mem.Allocator) ?[:0]u8 {
|
||||
var buf = this.writable();
|
||||
if (slice.len == 0) {
|
||||
buf[0] = 0;
|
||||
this.len += 1;
|
||||
return buf[0..0 :0];
|
||||
}
|
||||
|
||||
const result = bun.simdutf.convert.utf16.to.utf8.with_errors.le(slice, buf);
|
||||
if (result.status == .success) {
|
||||
this.len += result.count + 1;
|
||||
buf[result.count] = 0;
|
||||
return buf[0..result.count :0];
|
||||
} else {
|
||||
var list = std.ArrayList(u8).init(fallback_allocator);
|
||||
var out = bun.strings.toUTF8ListWithTypeBun(&list, []const u16, slice) catch return null;
|
||||
out.append(0) catch return null;
|
||||
return list.items[0 .. list.items.len - 1 :0];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
pub fn appendZ(this: *StringBuilder, slice: string) [:0]const u8 {
|
||||
|
||||
Reference in New Issue
Block a user