Skip to content

Commit

Permalink
Fix #73, handle a corner case in which a rstring_delimeter is missing…
Browse files Browse the repository at this point in the history
… and is possible to determine that it's a full string without cutting it to pieces
  • Loading branch information
mangiucugna committed Sep 28, 2024
1 parent 522a4ba commit 9ed7bf1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ requires = ["setuptools>=61.0"]
build-backend = "setuptools.build_meta"
[project]
name = "json_repair"
version = "0.29.5"
version = "0.29.6"
license = {file = "LICENSE"}
authors = [
{ name="Stefano Baccianella", email="4247706+mangiucugna@users.noreply.github.com" },
Expand Down
9 changes: 9 additions & 0 deletions src/json_repair/json_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,15 @@ def parse_string(self) -> Union[str, bool, None]:
next_c = self.get_char_at(i)
if next_c and next_c in [",", "}"]:
rstring_delimiter_missing = False
elif char == ",":
# We couldn't find any rstring_delimeter before the end of the string
# check if this is the last string of an object and therefore we can keep going
# make an exception if this is the last char before the closing brace
i = self.skip_to_character(character="}", idx=1)
if i > 1:
# Ok it's not right after the comma
# Let's ignore
rstring_delimiter_missing = False
if rstring_delimiter_missing:
self.log(
"While parsing a string missing the left delimiter in object value context, we found a , or } and we couldn't determine that a right delimiter was present. Stopping here",
Expand Down
1 change: 1 addition & 0 deletions tests/test_json_repair.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ def test_object_edge_cases():
assert repair_json('{"key": "Lorem "ipsum" s,"}') == '{"key": "Lorem \\"ipsum\\" s,"}'
assert repair_json('{"lorem": ipsum, sic, datum.",}') == '{"lorem": "ipsum, sic, datum."}'
assert repair_json('{"lorem": sic tamet. "ipsum": sic tamet, quick brown fox. "sic": ipsum}') == '{"lorem": "sic tamet.", "ipsum": "sic tamet", "sic": "ipsum"}'
assert repair_json('{"lorem_ipsum": "sic tamet, quick brown fox. }') == '{"lorem_ipsum": "sic tamet, quick brown fox."}'
assert repair_json('{"key":value, " key2":"value2" }') == '{"key": "value", " key2": "value2"}'
assert repair_json('{"key":value "key2":"value2" }') == '{"key": "value", "key2": "value2"}'

Expand Down

0 comments on commit 9ed7bf1

Please sign in to comment.