fix(windows): handle invalid utf16le in command line arguments (#11612)

This commit is contained in:
Jarred Sumner
2024-06-05 18:48:08 -07:00
committed by GitHub
parent 3e4c0918a4
commit bab8c0c0b2
2 changed files with 19 additions and 9 deletions

View File

@@ -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 {