Skip to content

Commit

Permalink
Fix #62, an off by one error made it impossible to deal with escape c…
Browse files Browse the repository at this point in the history
…haracters at the beginning of a string
  • Loading branch information
mangiucugna committed Aug 11, 2024
1 parent 359bb73 commit ce5731e
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ repos:
- id: mixed-line-ending
- id: end-of-file-fixer
- repo: https://github.com/pycqa/flake8
rev: 7.1.0
rev: 7.1.1
hooks:
- id: flake8
args: ["--extend-ignore=E203,E501", "--per-file-ignores=__init__.py:F401"]
Expand All @@ -17,7 +17,7 @@ repos:
- id: bandit
args: [ --exclude, tests ]
- repo: https://github.com/psf/black
rev: 24.4.2
rev: 24.8.0
hooks:
- id: black
#- repo: https://github.com/pre-commit/mirrors-mypy/
Expand Down
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.27.0"
version = "0.27.1"
license = {file = "LICENSE"}
authors = [
{ name="Stefano Baccianella", email="4247706+mangiucugna@users.noreply.github.com" },
Expand Down
2 changes: 1 addition & 1 deletion src/json_repair/json_repair.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ def parse_string(self) -> Union[str, JSONReturnType]:
string_acc += char
self.index += 1
char = self.get_char_at()
if len(string_acc) > 1 and string_acc[-1] == "\\":
if len(string_acc) > 0 and string_acc[-1] == "\\":
# This is a special case, if people use real strings this might happen
self.log("Found a stray escape sequence, normalizing it", "info")
string_acc = string_acc[:-1]
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 @@ -97,6 +97,7 @@ def test_missing_and_mixed_quotes():
assert repair_json('[{"key": "value", COMMENT "notes": "lorem "ipsum", sic."}]') == '[{"key": "value", "notes": "lorem \\"ipsum\\", sic."}]'
assert repair_json('{"key": ""value"}') == '{"key": "value"}'
assert repair_json('{"key": "value", 5: "value"}') == '{"key": "value", "5": "value"}'
assert repair_json('{"foo": "\\"bar\\""') == '{"foo": "\\"bar\\""}'

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

0 comments on commit ce5731e

Please sign in to comment.