diff --git a/crates/textimport/src/docx.rs b/crates/textimport/src/docx.rs index 4d90a6b7..87aaa335 100644 --- a/crates/textimport/src/docx.rs +++ b/crates/textimport/src/docx.rs @@ -186,8 +186,9 @@ fn run_attrs(rpr: Option<&El>) -> CharAttrs { if let Some(s) = r.on("strike") { a.strikethrough = Some(s); } - if let Some(sz) = r.val("sz").and_then(|v| v.parse::().ok()).filter(|v| v.is_finite()) { - a.size = Some(sz / 2.0); + // Half-points; sizes outside the engine's 0.1–1296 pt range (or non-finite) are dropped. + if let Some(pt) = r.val("sz").and_then(|v| v.parse::().ok()).map(|sz| sz / 2.0).filter(|pt| (0.1..=1296.0).contains(pt)) { + a.size = Some(pt); } if let Some(f) = r.child("rFonts").and_then(|f| f.attr("ascii").or(f.attr("hAnsi"))) { a.font_family = Some(f.to_string()); @@ -714,6 +715,19 @@ mod tests { } } + #[test] + fn out_of_range_sizes_are_dropped() { + let document = format!( + r#" + ab + "# + ); + let st = import(&docx(&document, "", "")).unwrap().story; + for at in [0, 1] { + assert_eq!(st.format_after(at).over.size, None, "run {at}"); + } + } + #[test] fn tracked_changes_import_as_accepted_including_moves() { // Regression (#256): text in a tracked move destination (`w:moveTo`) vanished on import.