Skip to content

Commit

Permalink
Bump 0.19.2, don't try to resolve to booleans inside the parse_string…
Browse files Browse the repository at this point in the history
… method if we are in object key context (keys are only string)
  • Loading branch information
mangiucugna committed May 21, 2024
1 parent be43db8 commit 40d2ce6
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
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.19.1"
version = "0.19.2"
license = {file = "LICENSE"}
authors = [
{ name="Stefano Baccianella", email="4247706+mangiucugna@users.noreply.github.com" },
Expand Down
3 changes: 2 additions & 1 deletion src/json_repair/json_repair.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,8 @@ def parse_string(self) -> str:
rstring_delimiter = "”"
elif char.isalpha():
# This could be a <boolean> and not a string. Because (T)rue or (F)alse or (N)ull are valid
if char.lower() in ["t", "f", "n"]:
# But remember, object keys are only of type string
if char.lower() in ["t", "f", "n"] and self.get_context() != "object_key":
value = self.parse_boolean_or_null()
if value != "":
return value
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 @@ -120,6 +120,7 @@ def test_object_edge_cases():
assert repair_json('{ "words": abcdef", "numbers": 12345", "words2": ghijkl" }') == '{"words": "abcdef", "numbers": 12345, "words2": "ghijkl"}'
assert repair_json('''{"number": 1,"reason": "According...""ans": "YES"}''') == '{"number": 1, "reason": "According...", "ans": "YES"}'
assert repair_json('''{ "a": "{ b": {} }" }''') == '{"a": "{ b"}'
assert repair_json("""{"b": "xxxxx" true}""") == '{"b": "xxxxx"}'

def test_number_edge_cases():
assert repair_json(' - { "test_key": ["test_value", "test_value2"] }') == '{"test_key": ["test_value", "test_value2"]}'
Expand Down

0 comments on commit 40d2ce6

Please sign in to comment.