Skip to content

Commit

Permalink
Fix #39, in the refactor of the string function I missed a corner cas…
Browse files Browse the repository at this point in the history
…e for empty strings and didn't have a test for it
  • Loading branch information
mangiucugna committed May 6, 2024
1 parent 83dca71 commit 2fcfefa
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 3 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.17.0"
version = "0.17.1"
license = {file = "LICENSE"}
authors = [
{ name="Stefano Baccianella", email="4247706+mangiucugna@users.noreply.github.com" },
Expand Down
4 changes: 4 additions & 0 deletions src/json_repair/json_repair.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,10 @@ def parse_string(self) -> str:
self.index += 1
char = self.get_char_at()

if not char:
# This is an empty string
return ""

# Ensuring we use the right delimiter
if char == "'":
lstring_delimiter = rstring_delimiter = "'"
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 @@ -4,6 +4,7 @@
def test_repair_json():
# Test with valid JSON strings
assert repair_json("[]") == "[]"
assert repair_json("[{]") == "[]"
assert repair_json(" { } ") == "{}"
assert repair_json("\"") == '""'
assert repair_json("\n") == '""'
Expand Down
4 changes: 2 additions & 2 deletions tests/test_performance.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def test_false_false_correct(benchmark):
mean_time = benchmark.stats.get("median")

# Define your time threshold in seconds
max_time = 45 / 10 ** 6 # 45 microsecond
max_time = 50 / 10 ** 6 # 50 microsecond

# Assert that the average time is below the threshold
assert mean_time < max_time, f"Benchmark exceeded threshold: {mean_time:.3f}s > {max_time:.3f}s"
Expand All @@ -97,7 +97,7 @@ def test_false_false_incorrect(benchmark):
mean_time = benchmark.stats.get("median")

# Define your time threshold in seconds
max_time = 13 / 10 ** 4 # 1.3 millisecond
max_time = 14 / 10 ** 4 # 1.4 millisecond

# Assert that the average time is below the threshold
assert mean_time < max_time, f"Benchmark exceeded threshold: {mean_time:.3f}s > {max_time:.3f}s"

0 comments on commit 2fcfefa

Please sign in to comment.