M12.AR15: never write a font family over 14 (review)

This commit is contained in:
Mouhand-Kaddo
2026-10-19 21:18:06 +04:00
parent 24b0b5d167
commit 6760e006ec
2 changed files with 10 additions and 1 deletions
+1 -1
View File
@@ -438,7 +438,7 @@ fn font_xml(f: &Font, dxf: bool, minor: bool) -> String {
s.push_str("<color theme=\"1\"/>");
}
if !dxf {
let family = f.family.unwrap_or(DEFAULT_FONT_FAMILY);
let family = f.family.filter(|v| *v <= MAX_FONT_FAMILY).unwrap_or(DEFAULT_FONT_FAMILY);
let _ = write!(s, "<name val=\"{}\"/><family val=\"{family}\"/>", esc_attr(&f.name));
if let Some(charset) = f.charset {
let _ = write!(s, "<charset val=\"{charset}\"/>");
+9
View File
@@ -1175,6 +1175,15 @@ fn out_of_range_family_is_ignored() {
let mut pkg = Package::open(&saved).unwrap();
let xml = String::from_utf8(pkg.read("xl/styles.xml").unwrap().unwrap()).unwrap();
assert!(xml.contains("<name val=\"Arial\"/><family val=\"2\"/>"), "{xml}");
let mut set_directly = wb.clone();
let wide = set_directly.styles.derive(StyleId::DEFAULT, |st| st.font.family = Some(200));
set_directly.sheet_mut(0).unwrap().set_value(CellRef::new(0, 0), Value::text("x"));
set_directly.sheet_mut(0).unwrap().set_style(CellRef::new(0, 0), wide);
let saved = write_xlsx(&set_directly).unwrap();
let mut pkg = Package::open(&saved).unwrap();
let xml = String::from_utf8(pkg.read("xl/styles.xml").unwrap().unwrap()).unwrap();
assert!(!xml.contains("<family val=\"200\"/>"), "{xml}");
}
#[test]