Ignore leading invalid unicode characters in response bodies in Response.text()

This commit is contained in:
Jarred Sumner
2021-09-27 21:03:00 -07:00
parent 13f6297312
commit 37ffe4501c
2 changed files with 10 additions and 4 deletions

View File

@@ -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);