diff options
author | 2021-09-27 21:03:00 -0700 | |
---|---|---|
committer | 2021-09-27 21:03:00 -0700 | |
commit | 37ffe4501c2618ca34d652d1db167794a1806592 (patch) | |
tree | 828847e5c619b4e1618c622c225793a5e7e349e7 | |
parent | 13f62973128aea9266b43cc2e0de1e7bf1768b52 (diff) | |
download | bun-37ffe4501c2618ca34d652d1db167794a1806592.tar.gz bun-37ffe4501c2618ca34d652d1db167794a1806592.tar.zst bun-37ffe4501c2618ca34d652d1db167794a1806592.zip |
Ignore leading invalid unicode characters in response bodies in Response.text()
-rw-r--r-- | src/http_client.zig | 4 | ||||
-rw-r--r-- | src/javascript/jsc/webcore/response.zig | 10 |
2 files changed, 10 insertions, 4 deletions
diff --git a/src/http_client.zig b/src/http_client.zig index 34525e846..fd7088ff4 100644 --- a/src/http_client.zig +++ b/src/http_client.zig @@ -35,7 +35,7 @@ header_entries: Headers.Entries, header_buf: string, url: URL, allocator: *std.mem.Allocator, -verbose: bool = true, +verbose: bool = false, pub fn init(allocator: *std.mem.Allocator, method: Method, url: URL, header_entries: Headers.Entries, header_buf: string) HTTPClient { return HTTPClient{ @@ -408,7 +408,7 @@ pub fn sendHTTPS(this: *HTTPClient, body_str: []const u8, body_out_str: *Mutable remaining_content_length -= size; } - body_out_str.list.items.len = body_size; + body_out_str.list.shrinkRetainingCapacity(body_size); } return response; diff --git a/src/javascript/jsc/webcore/response.zig b/src/javascript/jsc/webcore/response.zig index 8073921b1..df283060d 100644 --- a/src/javascript/jsc/webcore/response.zig +++ b/src/javascript/jsc/webcore/response.zig @@ -75,8 +75,14 @@ pub const Response = struct { (brk: { switch (this.body.value) { .Unconsumed => { - if (this.body.ptr) |_ptr| { - break :brk ZigString.init(_ptr[0..this.body.len]).toValue(VirtualMachine.vm.global); + if (this.body.len > 0) { + if (this.body.ptr) |_ptr| { + var offset: usize = 0; + while (offset < this.body.len and _ptr[offset] > 127 or strings.utf8ByteSequenceLength(_ptr[offset]) == 0) : (offset += 1) {} + if (offset < this.body.len) { + break :brk ZigString.init(_ptr[offset..this.body.len]).toValue(VirtualMachine.vm.global); + } + } } break :brk ZigString.init("").toValue(VirtualMachine.vm.global); |