Merge PR #1512: Reject formula number literals too large for f64 as parse errors

This commit is contained in:
aiongg
2026-10-22 02:35:56 +00:00
2 changed files with 11 additions and 0 deletions
+3
View File
@@ -260,6 +260,9 @@ pub fn tokenize_locale(src: &str, locale: crate::FormulaLocale) -> Result<Vec<To
.replace(locale.decimal_separator(), ".")
.parse()
.map_err(|_| LexError { msg: format!("bad number `{text}`"), pos: start })?;
if !v.is_finite() {
return Err(LexError { msg: format!("number too large `{text}`"), pos: start });
}
push(&mut out, Tok::Number(v), j);
i = j;
}
+8
View File
@@ -401,3 +401,11 @@ fn formulas_longer_than_excel_allows_are_refused() {
assert!(text.len() > crate::MAX_FORMULA_LEN);
assert!(parse(&text).is_ok());
}
#[test]
fn number_literal_too_large_for_f64_is_a_parse_error() {
for bad in ["1E+400", "-1E+400", "1E+400*A1", "SUM(1E309,1)", "9".repeat(400).as_str()] {
assert!(parse(bad).is_err(), "{bad} should fail");
}
assert!(parse("1E+308").is_ok());
}