From 9ed36445b924c028acf72854e6ca735abf5838cc Mon Sep 17 00:00:00 2001 From: Abdelrahman Farid Date: Tue, 19 Sep 2023 22:18:23 +0300 Subject: [PATCH 1/2] Add test for utf8 multibyte strings --- tests/core/encoding/json/test_core_json.odin | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/core/encoding/json/test_core_json.odin b/tests/core/encoding/json/test_core_json.odin index 937d1c738..23361d694 100644 --- a/tests/core/encoding/json/test_core_json.odin +++ b/tests/core/encoding/json/test_core_json.odin @@ -33,6 +33,7 @@ main :: proc() { marshal_json(&t) unmarshal_json(&t) surrogate(&t) + utf8_string_of_multibyte_characters(&t) fmt.printf("%v/%v tests successful.\n", TEST_count - TEST_fail, TEST_count) if TEST_fail > 0 { @@ -359,3 +360,10 @@ surrogate :: proc(t: ^testing.T) { 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)) } + +@test +utf8_string_of_multibyte_characters :: proc(t: ^testing.T) { + _, err := json.parse_string(`"🐛✅"`) + msg := fmt.tprintf("Expected `json.parse` to return nil, got %v", err) + expect(t, err == nil, msg) +} From f1872f495ad1e6abc695b78ee2cc3b1c0444cb8b Mon Sep 17 00:00:00 2001 From: Abdelrahman Farid Date: Tue, 19 Sep 2023 22:19:05 +0300 Subject: [PATCH 2/2] Fix bug with index increment in `unquote_string` --- core/encoding/json/parser.odin | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/encoding/json/parser.odin b/core/encoding/json/parser.odin index d007e16d7..bc381efee 100644 --- a/core/encoding/json/parser.odin +++ b/core/encoding/json/parser.odin @@ -343,7 +343,7 @@ unquote_string :: proc(token: Token, spec: Specification, allocator := context.a i += 1 continue } - r, w := utf8.decode_rune_in_string(s) + r, w := utf8.decode_rune_in_string(s[i:]) if r == utf8.RUNE_ERROR && w == 1 { break }