Skip to content

Commit

Permalink
fix: pass positive and negative incompleted float
Browse files Browse the repository at this point in the history
  • Loading branch information
iw4p committed Mar 27, 2024
1 parent 207d524 commit 632c126
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
10 changes: 6 additions & 4 deletions example.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
{"web-app":
{"servlet": [
{
"servlet-name3": "xyz",
"servlet-name4": null,
"number-one": 1.,
"number-two": 1.2,
"new-one": "xyz",
"servlet-name-null": null,
"servlet-name2": true,
"servlet-name1": false,
"servlet-name-true": true,
"servlet-name-false": false,
"servlet-class": "org.cofax.cds.CDSServlet",
"init-param": {
Expand Down
2 changes: 1 addition & 1 deletion partialjson/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"""
from .json_parser import JSONParser

__version__ = "0.0.6"
__version__ = "0.0.7"
__author__ = 'Nima Akbarzadeh'
__author_email__ = "[email protected]"
__license__ = "MIT"
Expand Down
9 changes: 6 additions & 3 deletions partialjson/json_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,13 @@ def parse_number(self, s, e):
i += 1
num_str = s[:i]
s = s[i:]
if not num_str or num_str.endswith('.') or num_str.endswith('-'):
return num_str, "" # Return the incomplete number as is
if not num_str or num_str == "-" or num_str == ".":
return num_str, ""
try:
num = float(num_str) if '.' in num_str or 'e' in num_str or 'E' in num_str else int(num_str)
if num_str.endswith('.'):
num = int(num_str[:-1])
else:
num = float(num_str) if '.' in num_str or 'e' in num_str or 'E' in num_str else int(num_str)
except ValueError:
raise e
return num, s
Expand Down

0 comments on commit 632c126

Please sign in to comment.