mirror of
https://github.com/storytold/gridcraft.git
synced 2026-10-31 22:26:57 -06:00
Reject formula number literals too large for f64 as parse errors
Found while testing crates/formula/src/lexer.rs:258 Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com> Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com> Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Haiku 5.5
parent
82ee02aac4
commit
1ab9e60d88
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user