Skip to content

Commit 7ba5155

Browse files
committed
fix: update JSONParser to handle incomplete unicode escapes and increment version to 0.1.0
1 parent 8a5d39a commit 7ba5155

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

partialjson/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from .json_parser import JSONParser
88

9-
__version__ = "0.0.9"
9+
__version__ = "0.1.0"
1010
__author__ = "Nima Akbarzadeh"
1111
__author_email__ = "iw4p@protonmail.com"
1212
__license__ = "MIT"

partialjson/json_parser.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,14 @@ def parse_string(self, s, e):
117117
return s[1:], ""
118118
return s[1:], ""
119119
else:
120-
# Check for incomplete escape sequences
120+
# Handle incomplete escape sequences
121121
if incomplete_escape_regex.match(s[1:]):
122-
return s[1:], ""
122+
return "", ""
123123
# Attempt to parse the string without incomplete escape sequences
124124
try:
125125
return json.loads(f'"{s[1:]}"'), ""
126126
except json.JSONDecodeError:
127-
return s[1:], ""
127+
return "", ""
128128
str_val = s[: end + 1]
129129
s = s[end + 1 :]
130130
if not self.strict:

test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,10 @@ def test_extra_space(self):
121121
# Unicode Tests
122122
def test_incomplete_unicode_escape(self):
123123
with self.assertRaises(Exception):
124-
self.parser_strict.parse('{"a":"\\', '{"a":"\\"')
125-
self.parser_strict.parse('{"a":"\\u', '{"a":"\\u"')
126-
self.parser_strict.parse('{"a":"\\u1', '{"a":"\\u1"')
127-
self.parser_strict.parse('{"a":"\\u123', '{"a":"\\u123"')
124+
self.parser_strict.parse('{"a":"\\', '{"a":""')
125+
self.parser_strict.parse('{"a":"\\u', '{"a":""')
126+
self.parser_strict.parse('{"a":"\\u1', '{"a":""')
127+
self.parser_strict.parse('{"a":"\\u123', '{"a":""')
128128

129129
def test_complete_unicode_escape(self):
130130
self.assertEqual(self.parser_strict.parse('{"a":"\\u0041"}').get("a"), "A")

0 commit comments

Comments
 (0)