mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-10-24 17:56:50 -06:00
Fix #3544: an artboard name XML can't hold falls back to the document title
Review follow-up (CodeRabbit): the blank-name check ran on the raw name, so a name made only of characters XML can't hold (control characters) wrote an empty <title>. The name is sanitised first, then the fallback applies. The title test covers such a name; it fails without the change.
This commit is contained in:
committed by
bflatastic
parent
439d32fcf8
commit
4f9b620dc6
@@ -134,11 +134,12 @@ fn write(doc: &Document, opts: &ExportOptions, native: Option<&[u8]>, id_prefix:
|
||||
out.push_str(&format!("</defs>{nl}"));
|
||||
}
|
||||
// An artboard exported on its own is named after it (#3544), else after the document.
|
||||
let board = opts.artboard.filter(|_| opts.artboard_title).and_then(|i| doc.artboards.get(i)).map(|a| a.name.as_str());
|
||||
let title = board.filter(|n| !n.trim().is_empty()).unwrap_or(&doc.title);
|
||||
// A name that is blank once the characters XML can't hold are dropped falls back too.
|
||||
let board = opts.artboard.filter(|_| opts.artboard_title).and_then(|i| doc.artboards.get(i)).map(|a| xml_text(&a.name));
|
||||
let title = board.filter(|n| !n.trim().is_empty()).unwrap_or_else(|| xml_text(&doc.title));
|
||||
if !title.is_empty() {
|
||||
out.push_str(&w.indent(1));
|
||||
out.push_str(&format!("<title>{}</title>{nl}", xml_text(title)));
|
||||
out.push_str(&format!("<title>{title}</title>{nl}"));
|
||||
}
|
||||
// File Info's description.
|
||||
if !doc.metadata.description.trim().is_empty() {
|
||||
|
||||
@@ -51,4 +51,7 @@ fn an_artboard_exported_alone_is_titled_after_it() {
|
||||
// An unnamed artboard falls back to the document's title.
|
||||
d.artboards[1].name = " ".into();
|
||||
assert_eq!(title(&d, alone(Some(1))).as_deref(), Some("<title>Icons</title>"));
|
||||
// So does one whose only characters can't appear in XML.
|
||||
d.artboards[1].name = "\u{1}\u{2}".into();
|
||||
assert_eq!(title(&d, alone(Some(1))).as_deref(), Some("<title>Icons</title>"));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user