Skip to content

Commit

Permalink
Add more guards to avoid evaluating an escaped delimeter
Browse files Browse the repository at this point in the history
  • Loading branch information
mangiucugna committed Sep 27, 2024
1 parent 6b6b0c8 commit 965ccf9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
exclude: ^tests/
files: \.py$
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
Expand Down
13 changes: 7 additions & 6 deletions src/json_repair/json_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,9 @@ def parse_string(self) -> Union[str, bool, None]:
string_acc += str(char)
self.index += 1
char = self.get_char_at()
elif next_c == rstring_delimiter:
elif (
next_c == rstring_delimiter and self.get_char_at(i - 1) != "\\"
):
if self.context.current == ContextValues.OBJECT_VALUE:
# But this might not be it! This could be just a missing comma
# We found a delimiter and we need to check if this is a key
Expand All @@ -449,11 +451,10 @@ def parse_string(self) -> Union[str, bool, None]:
i += 1
next_c = self.get_char_at(i)
while next_c and next_c != ":":
if next_c in [
lstring_delimiter,
rstring_delimiter,
",",
]:
if next_c == "," or (
next_c == rstring_delimiter
and self.get_char_at(i - 1) != "\\"
):
break
i += 1
next_c = self.get_char_at(i)
Expand Down

0 comments on commit 965ccf9

Please sign in to comment.