Reject invalid XML tag names in xml.mapStyle

Found while testing crates/engine/src/cmd/xml.rs:~290 (the xml.mapStyle command; the export is in export_xml)

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:
NetterSilver
2026-10-26 21:37:07 +00:00
co-authored by Claude Haiku 5.5
parent ed8aabd1dc
commit 4f03e10594
+18
View File
@@ -268,6 +268,11 @@ pub fn specs() -> Vec<CommandSpec> {
|s, p| {
let style = str_param(p, "style").unwrap_or("").to_string();
let tag = str_param(p, "tag").map(str::to_string);
if let Some(t) = &tag
&& !valid_name(t)
{
return Err(bad("xml.mapStyle", format!("`{t}` isn't a valid XML name")));
}
if s.doc()?.doc.styles.para(&style).is_none() {
return Err(bad("xml.mapStyle", format!("no paragraph style `{style}`")));
}
@@ -475,6 +480,19 @@ mod tests {
assert!(s.execute("xml.validate", &json!({})).is_err());
}
#[test]
fn map_style_rejects_invalid_tag_name() {
let mut s = Session::new();
s.execute("file.new", &json!({})).unwrap();
s.execute("style.paragraph.create", &json!({"name": "Head"})).unwrap();
assert!(s.execute("xml.mapStyle", &json!({"style": "Head", "tag": "a b><x"})).is_err());
let d = &s.doc().unwrap().doc;
assert!(d.xml.style_map.is_empty());
assert!(d.xml.tags.iter().all(|t| t.name != "a b><x"));
s.execute("xml.mapStyle", &json!({"style": "Head", "tag": "title"})).unwrap();
assert_eq!(s.doc().unwrap().doc.xml.style_map.len(), 1);
}
#[test]
fn tag_export_and_import_xml() {
let mut s = Session::new();