diff --git a/crates/doc/src/lib.rs b/crates/doc/src/lib.rs index a222e8e91..6fa9a2304 100644 --- a/crates/doc/src/lib.rs +++ b/crates/doc/src/lib.rs @@ -360,10 +360,12 @@ fn parse_measure(s: &str, default: Unit) -> Option { }; } } + // Plain decimals only, as in `number_unit` (`str::parse` would accept `1e5`, `inf`, `nan`). + let plain = |t: &str| t.trim().chars().all(|c| c.is_ascii_digit() || c == '.' || c == '-') && t.trim().parse::().is_ok(); if let Some((p, pt)) = s.split_once('p') && !p.is_empty() - && p.trim().parse::().is_ok() - && (pt.is_empty() || pt.trim().parse::().is_ok()) + && plain(p) + && (pt.is_empty() || plain(pt)) && !s.ends_with("pt") && !s.ends_with("px") { @@ -2713,6 +2715,13 @@ mod tests { assert_eq!(Unit::Points.parse("-2p"), Some(-24.0)); assert_eq!(Unit::Points.parse("2p6"), Some(30.0)); } + + #[test] + fn pica_form_rejects_exponent_notation() { + for s in ["1e5p", "infp", "nanp", "infp3", "1p1e2"] { + assert_eq!(Unit::Points.parse(s), None, "{s}"); + } + } } #[cfg(test)]