Skip to content

Commit

Permalink
Merge pull request #2804 from bytesiz3d/fix-unquote-string
Browse files Browse the repository at this point in the history
Fix bug with index increment in `core:encoding/json.unquote_string`
  • Loading branch information
gingerBill authored Sep 20, 2023
2 parents ecde06e + f1872f4 commit c23b582
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion core/encoding/json/parser.odin
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
8 changes: 8 additions & 0 deletions tests/core/encoding/json/test_core_json.odin
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}

0 comments on commit c23b582

Please sign in to comment.