Handle invalid utf8 when parsing json

This commit is contained in:
Brad Lewis
2026-05-10 16:17:39 +10:00
parent e70f846de0
commit 87d58b9fb7

View File

@@ -474,7 +474,10 @@ unquote_string :: proc(token: Token, spec: Specification, allocator := context.a
i += width
buf, buf_width := utf8.encode_rune(r)
assert(buf_width <= width)
// If we have an invalid utf8 character, width can be smaller than the width of RUNE_ERROR
if r != utf8.RUNE_ERROR {
assert(buf_width <= width)
}
copy(b[w:], buf[:buf_width])
w += buf_width
}