Reject signs and exponents in ExportSize::parse

Found while testing crates/doc/src/props.rs:1394 (ExportSize::parse, `num.parse::<f64>()`)

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:
NetterSilverandClaude Haiku 5.5 committed 2026-11-08 12:22:45 +00:00
1 parent 3635c23070
commit 6222fce8d1
2 files changed
+5 -1

No files matched your search

+4
View File
@@ -1399,6 +1399,10 @@ impl ExportSize {
Some((i, c)) if c.is_ascii_alphabetic() => (s.get(..i)?.trim(), Some(c)),
_ => (s.as_str(), None),
};
// Plain decimal only: no sign, exponent, "inf" or "nan".
if !num.bytes().all(|b| b.is_ascii_digit() || b == b'.') {
return None;
}
let value: f64 = num.parse().ok()?;
match unit {
None | Some('x') => ExportSize::Scale { value },
+1 -1
View File
@@ -283,7 +283,7 @@ fn export_sizes_parse_and_label() {
assert_eq!(ExportSize::parse(text), Some(want), "{text}");
assert_eq!(ExportSize::parse(&want.label()), Some(want));
}
for bad in ["", "x", "0x", "-1x", "NaNx", "infx", "65x", "20000w", "2q", "2xx"] {
for bad in ["", "x", "0x", "-1x", "NaNx", "infx", "65x", "20000w", "2q", "2xx", "+2x", "+512w", "2e0x", "2E0x", "+0.5x"] {
assert_eq!(ExportSize::parse(bad), None, "{bad}");
}
let e = |size, suffix: &str, format| ExportSetting { size, suffix: suffix.into(), format, ..Default::default() };