json-repair 0.19.0__tar.gz → 0.19.1__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.19.0
3
+ Version: 0.19.1
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.19.0"
6
+ version = "0.19.1"
7
7
  license = {file = "LICENSE"}
8
8
  authors = [
9
9
  { name="Stefano Baccianella", email="4247706+mangiucugna@users.noreply.github.com" },
@@ -309,6 +309,15 @@ class JSONParser:
309
309
  string_acc += char
310
310
  self.index += 1
311
311
  char = self.get_char_at()
312
+ if len(string_acc) > 1 and string_acc[-1] == "\\":
313
+ # This is a special case, if people use real strings this might happen
314
+ self.log("Found a stray escape sequence, normalizing it", "info")
315
+ string_acc = string_acc[:-1]
316
+ if char in [rstring_delimiter, "t", "n", "r", "b", "\\"]:
317
+ escape_seqs = {"t": "\t", "n": "\n", "r": "\r", "b": "\b"}
318
+ string_acc += escape_seqs.get(char, char)
319
+ self.index += 1
320
+ char = self.get_char_at()
312
321
  # ChatGPT sometimes forget to quote stuff in html tags or markdown, so we do this whole thing here
313
322
  if char == rstring_delimiter:
314
323
  # Special case here, in case of double quotes one after another
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: json_repair
3
- Version: 0.19.0
3
+ Version: 0.19.1
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
@@ -59,7 +59,7 @@ def test_repair_json():
59
59
  assert repair_json('{"') == '{}'
60
60
  assert repair_json('["') == '[]'
61
61
  assert repair_json("'\"'") == '"\\\""'
62
- assert repair_json("{\"key\": 'string\"\n\t\le'") == '{"key": "string\\"\\n\\t\\\\le"}'
62
+ assert repair_json("{\"key\": 'string\"\n\t\le'") == '{"key": "string\\"\\n\\tle"}'
63
63
  assert repair_json('{foo: [}') == '{"foo": []}'
64
64
  assert repair_json('''{ "a": "{ b": {} }" }''') == '{"a": "{ b"}'
65
65
  assert repair_json('{"key": "value:value"}') == '{"key": "value:value"}'
@@ -110,7 +110,7 @@ def test_repair_json():
110
110
  { "key": "value" }
111
111
  ```""") == '{"key": "value"}'
112
112
  assert repair_json('````{ "key": "value" }```') == '{"key": "value"}'
113
- assert repair_json(r'{"real_content": "Some string: Some other string Some string <a href=\"https://domain.com\">Some link</a>"') == r'{"real_content": "Some string: Some other string Some string <a href=\\\"https://domain.com\\\">Some link</a>"}'
113
+ assert repair_json(r'{"real_content": "Some string: Some other string \t Some string <a href=\"https://domain.com\">Some link</a>"') == r'{"real_content": "Some string: Some other string \t Some string <a href=\"https://domain.com\">Some link</a>"}'
114
114
  assert repair_json('{"key_1\n": "value"}') == '{"key_1": "value"}'
115
115
  assert repair_json('{"key\t_": "value"}') == '{"key\\t_": "value"}'
116
116
  assert repair_json('{""answer"":[{""traits"":''Female aged 60+'',""answer1"":""5""}]}') == '{"answer": [{"traits": "Female aged 60+", "answer1": "5"}]}'
File without changes
File without changes
File without changes