fix: handle invalid numeric API parameters (#2433)

This commit is contained in:
yhz5613813
2026-09-05 00:44:34 +08:00
committed by GitHub
parent 9bc9203da5
commit db5d5bfe5f
2 changed files with 43 additions and 3 deletions
+4 -3
View File
@@ -1152,14 +1152,15 @@ def tryparseint(value,fallback):
return 0
try:
return int(value)
except ValueError:
except (TypeError, ValueError, OverflowError):
return fallback
def tryparsefloat(value,fallback):
if value is None:
return fallback
try:
return float(value)
except ValueError:
parsed = float(value)
return parsed if math.isfinite(parsed) else fallback
except (TypeError, ValueError, OverflowError):
return fallback
def replace_last_in_string(text: str, match: str, replacement: str) -> str: