Fix: dirty_jason.py the _parse_number method will gracefully handle cases where the parsed string is just '+', '-', or empty, returning it as a string instead of raising a ValueError.

deci committed May 12, 2025 at 13:26 UTC b1d77cd4ef471f763cdaa093684b021b059b36df
1 file changed +9 -1
python/helpers/dirty_json.py
+9 -1
@@ -252,10 +252,18 @@ class DirtyJson:
252 while self.current_char is not None and (self.current_char.isdigit() or self.current_char in ['-', '+', '.', 'e', 'E']):
253 number_str += self.current_char
254 self._advance()
255 + # Only try to convert if number_str is a valid number
256 + if number_str in ('', '+', '-'):
257 + # Not a valid number, treat as string or handle error
258 + return number_str.strip() # or raise ValueError("Invalid number format")
259 try:
260 return int(number_str)
261 except ValueError:
258 - return float(number_str)
262 + try:
263 + return float(number_str)
264 + except ValueError:
265 + # Not a valid number, treat as string or handle error
266 + return number_str.strip() # or raise ValueError("Invalid number format")
267
268 def _parse_unquoted_string(self):
269 result = ""