diff options
author | 2022-11-27 22:08:30 -0800 | |
---|---|---|
committer | 2022-11-27 22:08:30 -0800 | |
commit | ede2a494bc621496f990954f56e829c8dbe5bb47 (patch) | |
tree | 84ca83bce360a53d8a30e9ae264d68cee87a9bb4 /src | |
parent | 48df99c496656d02f90ec4802383851d403c78ad (diff) | |
download | bun-ede2a494bc621496f990954f56e829c8dbe5bb47.tar.gz bun-ede2a494bc621496f990954f56e829c8dbe5bb47.tar.zst bun-ede2a494bc621496f990954f56e829c8dbe5bb47.zip |
Fix UTF16 bug in `await fetch().text()`
Diffstat (limited to 'src')
-rw-r--r-- | src/bun.js/webcore/response.zig | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/src/bun.js/webcore/response.zig b/src/bun.js/webcore/response.zig index 7e014d426..936a5e464 100644 --- a/src/bun.js/webcore/response.zig +++ b/src/bun.js/webcore/response.zig @@ -4154,19 +4154,16 @@ pub const InternalBlob = struct { was_string: bool = false, pub fn toStringOwned(this: *@This(), globalThis: *JSC.JSGlobalObject) JSValue { - var str = ZigString.init(this.sliceConst()); - - if (strings.isAllASCII(this.sliceConst())) { - this.bytes.items = &.{}; - this.bytes.capacity = 0; + if (strings.toUTF16Alloc(globalThis.allocator(), this.bytes.items, false) catch &[_]u16{}) |out| { + const return_value = ZigString.toExternalU16(out.ptr, out.len, globalThis); + return_value.ensureStillAlive(); + this.deinit(); + return return_value; + } else { + var str = ZigString.init(this.toOwnedSlice()); + str.mark(); return str.toExternalValue(globalThis); } - - str.markUTF8(); - const out = str.toValueGC(globalThis); - out.ensureStillAlive(); - this.deinit(); - return out; } pub inline fn sliceConst(this: *const @This()) []const u8 { |