json-repair 0.17.2__tar.gz → 0.17.4__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: json_repair
3
- Version: 0.17.2
3
+ Version: 0.17.4
4
4
  Summary: A package to repair broken json strings
5
5
  Author-email: Stefano Baccianella <4247706+mangiucugna@users.noreply.github.com>
6
6
  License: MIT License
@@ -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.17.2"
6
+ version = "0.17.4"
7
7
  license = {file = "LICENSE"}
8
8
  authors = [
9
9
  { name="Stefano Baccianella", email="4247706+mangiucugna@users.noreply.github.com" },
@@ -113,6 +113,7 @@ class JSONParser:
113
113
  # <member> starts with a <string>
114
114
  key = ""
115
115
  while key == "" and self.get_char_at():
116
+ current_index = self.index
116
117
  key = self.parse_string()
117
118
 
118
119
  # This can happen sometimes like { "": "value" }
@@ -123,7 +124,8 @@ class JSONParser:
123
124
  "info",
124
125
  )
125
126
  break
126
- elif key == "":
127
+ elif key == "" and self.index == current_index:
128
+ # Sometimes the string search might not move the index at all, that might lead us to an infinite loop
127
129
  self.index += 1
128
130
 
129
131
  # We reached the end here
@@ -378,14 +380,20 @@ class JSONParser:
378
380
  def parse_number(self) -> Union[float, int, str]:
379
381
  # <number> is a valid real number expressed in one of a number of given formats
380
382
  number_str = ""
381
- number_chars = set("0123456789-.eE/")
383
+ number_chars = set("0123456789-.eE/,")
382
384
  char = self.get_char_at()
383
385
  while char and char in number_chars:
384
386
  number_str += char
385
387
  self.index += 1
386
388
  char = self.get_char_at()
389
+ if len(number_str) > 1 and number_str[-1] in "-eE/,":
390
+ # The number ends with a non valid character for a number/currency, rolling back one
391
+ number_str = number_str[:-1]
392
+ self.index -= 1
387
393
  if number_str:
388
394
  try:
395
+ if "," in number_str:
396
+ return str(number_str)
389
397
  if "." in number_str or "e" in number_str or "E" in number_str:
390
398
  return float(number_str)
391
399
  elif number_str == "-":
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: json_repair
3
- Version: 0.17.2
3
+ Version: 0.17.4
4
4
  Summary: A package to repair broken json strings
5
5
  Author-email: Stefano Baccianella <4247706+mangiucugna@users.noreply.github.com>
6
6
  License: MIT License
@@ -56,7 +56,7 @@ def test_repair_json():
56
56
  assert repair_json('{"') == '{}'
57
57
  assert repair_json('["') == '[]'
58
58
  assert repair_json("'\"'") == '"\\\""'
59
- assert repair_json("'string\"\n\t\le") == '"string\\\"\\n\\t\\\\le"'
59
+ assert repair_json("{\"key\": 'string\"\n\t\le'") == '{"key": "string\\"\\n\\t\\\\le"}'
60
60
  assert repair_json('{foo: [}') == '{"foo": []}'
61
61
  assert repair_json('''{ "a": "{ b": {} }" }''') == '{"a": "{ b"}'
62
62
  assert repair_json('{"key": "value:value"}') == '{"key": "value:value"}'
@@ -121,6 +121,8 @@ def test_repair_json():
121
121
  assert repair_json('{"key": 1/3, "foo": "bar"}') == '{"key": "1/3", "foo": "bar"}'
122
122
  assert repair_json('{"here": "now", "key": 1/3, "foo": "bar"}') == '{"here": "now", "key": "1/3", "foo": "bar"}'
123
123
  assert repair_json('{"key": 12345/67890}') == '{"key": "12345/67890"}'
124
+ assert repair_json('[105,12') == '["105,12"]'
125
+ assert repair_json('{"key", 105,12,') == '{"key": "105,12"}'
124
126
 
125
127
 
126
128
  def test_repair_json_with_objects():
File without changes
File without changes
File without changes