Merge pull request #2120 from Silvertree2010/fix/h11642-exportsize-parse-accepts-a-sign

Reject signs and exponents in ExportSize::parse
This commit is contained in:
BFlat authored and GitHub committed 2026-11-12 09:17:41 +07:00
commit d3138da22f
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() };