json-repair 0.29.7__tar.gz → 0.29.9__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.
Files changed (20) hide show
  1. {json_repair-0.29.7/src/json_repair.egg-info → json_repair-0.29.9}/PKG-INFO +1 -1
  2. {json_repair-0.29.7 → json_repair-0.29.9}/pyproject.toml +1 -1
  3. {json_repair-0.29.7 → json_repair-0.29.9}/src/json_repair/json_parser.py +12 -2
  4. {json_repair-0.29.7 → json_repair-0.29.9/src/json_repair.egg-info}/PKG-INFO +1 -1
  5. {json_repair-0.29.7 → json_repair-0.29.9}/tests/test_json_repair.py +2 -0
  6. {json_repair-0.29.7 → json_repair-0.29.9}/LICENSE +0 -0
  7. {json_repair-0.29.7 → json_repair-0.29.9}/README.md +0 -0
  8. {json_repair-0.29.7 → json_repair-0.29.9}/setup.cfg +0 -0
  9. {json_repair-0.29.7 → json_repair-0.29.9}/src/json_repair/__init__.py +0 -0
  10. {json_repair-0.29.7 → json_repair-0.29.9}/src/json_repair/__main__.py +0 -0
  11. {json_repair-0.29.7 → json_repair-0.29.9}/src/json_repair/json_context.py +0 -0
  12. {json_repair-0.29.7 → json_repair-0.29.9}/src/json_repair/json_repair.py +0 -0
  13. {json_repair-0.29.7 → json_repair-0.29.9}/src/json_repair/py.typed +0 -0
  14. {json_repair-0.29.7 → json_repair-0.29.9}/src/json_repair/string_file_wrapper.py +0 -0
  15. {json_repair-0.29.7 → json_repair-0.29.9}/src/json_repair.egg-info/SOURCES.txt +0 -0
  16. {json_repair-0.29.7 → json_repair-0.29.9}/src/json_repair.egg-info/dependency_links.txt +0 -0
  17. {json_repair-0.29.7 → json_repair-0.29.9}/src/json_repair.egg-info/entry_points.txt +0 -0
  18. {json_repair-0.29.7 → json_repair-0.29.9}/src/json_repair.egg-info/top_level.txt +0 -0
  19. {json_repair-0.29.7 → json_repair-0.29.9}/tests/test_coverage.py +0 -0
  20. {json_repair-0.29.7 → json_repair-0.29.9}/tests/test_performance.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: json_repair
3
- Version: 0.29.7
3
+ Version: 0.29.9
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.29.7"
6
+ version = "0.29.9"
7
7
  license = {file = "LICENSE"}
8
8
  authors = [
9
9
  { name="Stefano Baccianella", email="4247706+mangiucugna@users.noreply.github.com" },
@@ -291,6 +291,7 @@ class JSONParser:
291
291
  # * It iterated over the entire sequence
292
292
  # * If we are fixing missing quotes in an object, when it finds the special terminators
293
293
  char = self.get_char_at()
294
+ unmatched_delimiter = False
294
295
  while char and char != rstring_delimiter:
295
296
  if (
296
297
  missing_quotes
@@ -317,11 +318,13 @@ class JSONParser:
317
318
  if next_c and next_c in [",", "}"]:
318
319
  rstring_delimiter_missing = False
319
320
  elif char == ",":
321
+ # skip any whitespace first
322
+ i = self.skip_whitespaces_at(idx=1, move_main_index=False)
320
323
  # We couldn't find any rstring_delimeter before the end of the string
321
324
  # check if this is the last string of an object and therefore we can keep going
322
325
  # make an exception if this is the last char before the closing brace
323
- i = self.skip_to_character(character="}", idx=1)
324
- if i > 1:
326
+ j = self.skip_to_character(character="}", idx=i)
327
+ if j - i > 1:
325
328
  # Ok it's not right after the comma
326
329
  # Let's ignore
327
330
  rstring_delimiter_missing = False
@@ -377,6 +380,11 @@ class JSONParser:
377
380
  "In a string with missing quotes and object value context, I found a delimeter but it turns out it was the beginning on the next key. Stopping here.",
378
381
  )
379
382
  break
383
+ elif unmatched_delimiter:
384
+ unmatched_delimiter = False
385
+ string_acc += str(char)
386
+ self.index += 1
387
+ char = self.get_char_at()
380
388
  else:
381
389
  # Check if eventually there is a rstring delimiter, otherwise we bail
382
390
  i = 1
@@ -430,6 +438,7 @@ class JSONParser:
430
438
  self.log(
431
439
  "While parsing a string, we misplaced a quote that would have closed the string but has a different meaning here since this is the last element of the object, ignoring it",
432
440
  )
441
+ unmatched_delimiter = not unmatched_delimiter
433
442
  string_acc += str(char)
434
443
  self.index += 1
435
444
  char = self.get_char_at()
@@ -459,6 +468,7 @@ class JSONParser:
459
468
  self.log(
460
469
  "While parsing a string, we a misplaced quote that would have closed the string but has a different meaning here, ignoring it",
461
470
  )
471
+ unmatched_delimiter = not unmatched_delimiter
462
472
  string_acc += str(char)
463
473
  self.index += 1
464
474
  char = self.get_char_at()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: json_repair
3
- Version: 0.29.7
3
+ Version: 0.29.9
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
@@ -106,6 +106,8 @@ def test_missing_and_mixed_quotes():
106
106
  assert repair_json('{"foo": "\\"bar\\""') == '{"foo": "\\"bar\\""}'
107
107
  assert repair_json('{"" key":"val"') == '{" key": "val"}'
108
108
  assert repair_json('{"key": value "key2" : "value2" ') == '{"key": "value", "key2": "value2"}'
109
+ assert repair_json('{"key": "lorem ipsum ... "sic " tamet. ...}') == '{"key": "lorem ipsum ... \\"sic \\" tamet. ..."}'
110
+ assert repair_json('{"key": value , }') == '{"key": "value"}'
109
111
 
110
112
  def test_array_edge_cases():
111
113
  assert repair_json("[1, 2, 3,") == "[1, 2, 3]"
File without changes
File without changes
File without changes