Skip to content

Commit

Permalink
x.json2: fix encoding of 馃拃馃悎 etc emojis (fix #20243) (#20247)
Browse files Browse the repository at this point in the history
  • Loading branch information
spytheman committed Dec 21, 2023
1 parent ed754cf commit 944b955
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
6 changes: 4 additions & 2 deletions vlib/x/json2/encoder.v
Expand Up @@ -574,8 +574,10 @@ fn (e &Encoder) encode_string(s string, mut wr io.Writer) ! {
wr.write(hex_code)!
} else {
// TODO: still figuring out what
// to do with more than 4 chars
wr.write(json2.space_bytes)!
// to do with more than 4 chars.
// According to https://www.json.org/json-en.html however, any codepoint is valid inside a string,
// so just passing it along should hopefully also work.
wr.write(slice.bytes())!
}
unsafe {
slice.free()
Expand Down
3 changes: 2 additions & 1 deletion vlib/x/json2/encoder_test.v
Expand Up @@ -34,7 +34,8 @@ fn test_json_string() {

fn test_json_string_emoji() {
text := json.Any('馃悎')
assert text.json_str() == r'" "'
assert text.json_str() == r'"馃悎"'
assert json.Any('馃拃').json_str() == r'"馃拃"'
}

fn test_json_string_non_ascii() {
Expand Down

0 comments on commit 944b955

Please sign in to comment.