fix #2550 json encoding should use surrogate pairs per RFC7159

This commit is contained in:
Laytan Laats
2023-05-22 17:22:33 +02:00
parent 118ab60588
commit 5d54b710e7
5 changed files with 54 additions and 13 deletions
+15 -1
View File
@@ -32,6 +32,7 @@ main :: proc() {
parse_json(&t)
marshal_json(&t)
unmarshal_json(&t)
surrogate(&t)
fmt.printf("%v/%v tests successful.\n", TEST_count - TEST_fail, TEST_count)
if TEST_fail > 0 {
@@ -344,4 +345,17 @@ unmarshal_json :: proc(t: ^testing.T) {
for p, i in g.products {
expect(t, p == original_data.products[i], "Producted unmarshaled improperly")
}
}
}
@test
surrogate :: proc(t: ^testing.T) {
input := `+ + * 😃 - /`
out, err := json.marshal(input)
expect(t, err == nil, fmt.tprintf("Expected `json.marshal(%q)` to return a nil error, got %v", input, err))
back: string
uerr := json.unmarshal(out, &back)
expect(t, uerr == nil, fmt.tprintf("Expected `json.unmarshal(%q)` to return a nil error, got %v", string(out), uerr))
expect(t, back == input, fmt.tprintf("Expected `json.unmarshal(%q)` to return %q, got %v", string(out), input, uerr))
}