x.json2: fix `json_string` for utf8 codepoints, add regression test
parent
04221475d1
commit
58df35b453
|
@ -156,7 +156,10 @@ fn json_string(s string) string {
|
|||
} else {
|
||||
slice := s[i..i + char_len]
|
||||
hex_code := slice.utf32_code().hex()
|
||||
if hex_code.len == 4 {
|
||||
if hex_code.len < 4 {
|
||||
// an utf8 codepoint
|
||||
sb.write_string(slice)
|
||||
} else if hex_code.len == 4 {
|
||||
sb.write_string('\\u$hex_code')
|
||||
} else {
|
||||
// TODO: still figuring out what
|
||||
|
|
|
@ -19,3 +19,11 @@ fn test_json_string_non_ascii() {
|
|||
text := json2.Any('ひらがな')
|
||||
assert text.json_str() == r'\u3072\u3089\u304c\u306a'
|
||||
}
|
||||
|
||||
fn test_utf8_strings_are_not_modified() ? {
|
||||
original := '{"s":"Schilddrüsenerkrankungen"}'
|
||||
// dump(original)
|
||||
deresult := json2.raw_decode(original) ?
|
||||
// dump(deresult)
|
||||
assert deresult.str() == original
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue