json-repair 0.41.1__tar.gz → 0.42.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {json_repair-0.41.1/src/json_repair.egg-info → json_repair-0.42.0}/PKG-INFO +1 -1
- {json_repair-0.41.1 → json_repair-0.42.0}/pyproject.toml +5 -2
- {json_repair-0.41.1 → json_repair-0.42.0}/src/json_repair/json_parser.py +6 -2
- {json_repair-0.41.1 → json_repair-0.42.0/src/json_repair.egg-info}/PKG-INFO +1 -1
- {json_repair-0.41.1 → json_repair-0.42.0}/tests/test_json_repair.py +5 -0
- {json_repair-0.41.1 → json_repair-0.42.0}/LICENSE +0 -0
- {json_repair-0.41.1 → json_repair-0.42.0}/README.md +0 -0
- {json_repair-0.41.1 → json_repair-0.42.0}/setup.cfg +0 -0
- {json_repair-0.41.1 → json_repair-0.42.0}/src/json_repair/__init__.py +0 -0
- {json_repair-0.41.1 → json_repair-0.42.0}/src/json_repair/__main__.py +0 -0
- {json_repair-0.41.1 → json_repair-0.42.0}/src/json_repair/json_context.py +0 -0
- {json_repair-0.41.1 → json_repair-0.42.0}/src/json_repair/json_repair.py +0 -0
- {json_repair-0.41.1 → json_repair-0.42.0}/src/json_repair/object_comparer.py +0 -0
- {json_repair-0.41.1 → json_repair-0.42.0}/src/json_repair/py.typed +0 -0
- {json_repair-0.41.1 → json_repair-0.42.0}/src/json_repair/string_file_wrapper.py +0 -0
- {json_repair-0.41.1 → json_repair-0.42.0}/src/json_repair.egg-info/SOURCES.txt +0 -0
- {json_repair-0.41.1 → json_repair-0.42.0}/src/json_repair.egg-info/dependency_links.txt +0 -0
- {json_repair-0.41.1 → json_repair-0.42.0}/src/json_repair.egg-info/entry_points.txt +0 -0
- {json_repair-0.41.1 → json_repair-0.42.0}/src/json_repair.egg-info/top_level.txt +0 -0
- {json_repair-0.41.1 → json_repair-0.42.0}/tests/test_coverage.py +0 -0
- {json_repair-0.41.1 → json_repair-0.42.0}/tests/test_performance.py +0 -0
@@ -3,7 +3,7 @@ requires = ["setuptools>=61.0"]
|
|
3
3
|
build-backend = "setuptools.build_meta"
|
4
4
|
[project]
|
5
5
|
name = "json_repair"
|
6
|
-
version = "0.
|
6
|
+
version = "0.42.0"
|
7
7
|
license = {file = "LICENSE"}
|
8
8
|
authors = [
|
9
9
|
{ name="Stefano Baccianella", email="4247706+mangiucugna@users.noreply.github.com" },
|
@@ -39,4 +39,7 @@ json_repair = "json_repair.__main__:cli"
|
|
39
39
|
# Pylint - PLC, PLE, PLW
|
40
40
|
# isort - I
|
41
41
|
select = ['E', 'F', 'W', 'A', 'PLC', 'PLE', 'PLW', 'I']
|
42
|
-
ignore = ["E501"]
|
42
|
+
ignore = ["E501"]
|
43
|
+
[tool.ruff.lint.per-file-ignores]
|
44
|
+
# Explicit re-exports is fine in __init__.py, still a code smell elsewhere.
|
45
|
+
"__init__.py" = ["PLC0414"]
|
@@ -10,7 +10,6 @@ JSONReturnType = Union[Dict[str, Any], List[Any], str, float, int, bool, None]
|
|
10
10
|
class JSONParser:
|
11
11
|
# Constants
|
12
12
|
STRING_DELIMITERS = ['"', "'", "“", "”"]
|
13
|
-
NUMBER_CHARS = set("0123456789-.eE/,")
|
14
13
|
|
15
14
|
def __init__(
|
16
15
|
self,
|
@@ -663,7 +662,8 @@ class JSONParser:
|
|
663
662
|
number_str = ""
|
664
663
|
char = self.get_char_at()
|
665
664
|
is_array = self.context.current == ContextValues.ARRAY
|
666
|
-
|
665
|
+
NUMBER_CHARS = set("0123456789-.eE/,")
|
666
|
+
while char and char in NUMBER_CHARS and (not is_array or char != ","):
|
667
667
|
number_str += char
|
668
668
|
self.index += 1
|
669
669
|
char = self.get_char_at()
|
@@ -671,6 +671,10 @@ class JSONParser:
|
|
671
671
|
# The number ends with a non valid character for a number/currency, rolling back one
|
672
672
|
number_str = number_str[:-1]
|
673
673
|
self.index -= 1
|
674
|
+
elif (self.get_char_at() or "").isalpha():
|
675
|
+
# this was a string instead, sorry
|
676
|
+
self.index -= len(number_str)
|
677
|
+
return self.parse_string()
|
674
678
|
try:
|
675
679
|
if "," in number_str:
|
676
680
|
return str(number_str)
|
@@ -179,6 +179,11 @@ def test_number_edge_cases():
|
|
179
179
|
assert repair_json('{"key": 10-20}') == '{"key": "10-20"}'
|
180
180
|
assert repair_json('{"key": 1.1.1}') == '{"key": "1.1.1"}'
|
181
181
|
assert repair_json('[- ') == '[]'
|
182
|
+
assert repair_json('{"key": 1. }') == '{"key": 1.0}'
|
183
|
+
assert repair_json('{"key": 1e10 }') == '{"key": 10000000000.0}'
|
184
|
+
assert repair_json('{"key": 1e }') == '{"key": 1}'
|
185
|
+
assert repair_json('{"key": 1notanumber }') == '{"key": "1notanumber"}'
|
186
|
+
assert repair_json('[1, 2notanumber]') == '[1, "2notanumber"]'
|
182
187
|
|
183
188
|
def test_markdown():
|
184
189
|
assert repair_json('{ "content": "[LINK]("https://google.com")" }') == '{"content": "[LINK](\\"https://google.com\\")"}'
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|