mirror of
https://github.com/storytold/gridcraft.git
synced 2026-10-29 21:26:48 -06:00
Merge PR #1512: Reject formula number literals too large for f64 as parse errors
This commit is contained in:
@@ -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