Skip to content

Commit

Permalink
Fix #75, fix yet another combination of misplaced quotes
Browse files Browse the repository at this point in the history
  • Loading branch information
mangiucugna committed Oct 4, 2024
1 parent fbe8963 commit b4d1ab0
Show file tree
Hide file tree
Showing 3 changed files with 10 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.7"
version = "0.29.8"
license = {file = "LICENSE"}
authors = [
{ name="Stefano Baccianella", email="4247706+mangiucugna@users.noreply.github.com" },
Expand Down
8 changes: 8 additions & 0 deletions src/json_repair/json_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ def parse_string(self) -> Union[str, bool, None]:
# * It iterated over the entire sequence
# * If we are fixing missing quotes in an object, when it finds the special terminators
char = self.get_char_at()
unmatched_delimiter = False
while char and char != rstring_delimiter:
if (
missing_quotes
Expand Down Expand Up @@ -377,6 +378,11 @@ def parse_string(self) -> Union[str, bool, None]:
"In a string with missing quotes and object value context, I found a delimeter but it turns out it was the beginning on the next key. Stopping here.",
)
break
elif unmatched_delimiter:
unmatched_delimiter = False
string_acc += str(char)
self.index += 1
char = self.get_char_at()
else:
# Check if eventually there is a rstring delimiter, otherwise we bail
i = 1
Expand Down Expand Up @@ -430,6 +436,7 @@ def parse_string(self) -> Union[str, bool, None]:
self.log(
"While parsing a string, we misplaced a quote that would have closed the string but has a different meaning here since this is the last element of the object, ignoring it",
)
unmatched_delimiter = not unmatched_delimiter
string_acc += str(char)
self.index += 1
char = self.get_char_at()
Expand Down Expand Up @@ -459,6 +466,7 @@ def parse_string(self) -> Union[str, bool, None]:
self.log(
"While parsing a string, we a misplaced quote that would have closed the string but has a different meaning here, ignoring it",
)
unmatched_delimiter = not unmatched_delimiter
string_acc += str(char)
self.index += 1
char = self.get_char_at()
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 @@ -106,6 +106,7 @@ def test_missing_and_mixed_quotes():
assert repair_json('{"foo": "\\"bar\\""') == '{"foo": "\\"bar\\""}'
assert repair_json('{"" key":"val"') == '{" key": "val"}'
assert repair_json('{"key": value "key2" : "value2" ') == '{"key": "value", "key2": "value2"}'
assert repair_json('{"key": "lorem ipsum ... "sic " tamet. ...}') == '{"key": "lorem ipsum ... \\"sic \\" tamet. ..."}'

def test_array_edge_cases():
assert repair_json("[1, 2, 3,") == "[1, 2, 3]"
Expand Down

0 comments on commit b4d1ab0

Please sign in to comment.