Skip to content

Commit

Permalink
fix(errors): adjust column offset if not at char boundary
Browse files Browse the repository at this point in the history
  • Loading branch information
akx authored and ijl committed Jan 21, 2022
1 parent d0016cd commit 853ffbd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/deserialize/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,13 @@ impl<'a> DeserializeError<'a> {
// directly use the `column` field
if self.column == 0 { return 0; }

let chars_count = s[..self.column - 1].chars().count();
// Find a column we can safely slice on
let mut column = self.column - 1;
while column > 0 && !s.is_char_boundary(column) {
column -= 1;
}

let chars_count = s[..column].chars().count();
if chars_count == s.chars().count() - 1 {
chars_count + 1
} else {
Expand Down
11 changes: 11 additions & 0 deletions test/test_issue221.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import pytest
import orjson


@pytest.mark.parametrize("input", [
b'"\xc8\x93',
b'"\xc8',
])
def test_invalid(input):
with pytest.raises(orjson.JSONDecodeError):
orjson.loads(input)

0 comments on commit 853ffbd

Please sign in to comment.