mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-17 15:26:12 +00:00
fix: preserve XML and raster import semantics after codec cutover
This commit is contained in:
@@ -165,7 +165,8 @@ fn parse(xml: &str, name: &str, cmd: &str) -> Result<El> {
|
||||
doctype: Doctype::Reject,
|
||||
limits: Limits { max_depth: MAX_NESTING, max_nodes: MAX_NODES as usize, ..Limits::DEFAULT },
|
||||
..Options::default()
|
||||
};
|
||||
}
|
||||
.strict();
|
||||
opts.parse(xml.as_bytes()).map_err(|e| match e {
|
||||
craft_xml::Error::TooDeep(_) => bad(cmd, format!("`{name}` in the Word document nests elements more than {MAX_NESTING} deep")),
|
||||
_ => bad(cmd, format!("`{name}` in the Word document is not well-formed XML: {e}")),
|
||||
|
||||
@@ -202,7 +202,8 @@ fn parse_library(xml: &str, cmd: &str) -> Result<Library> {
|
||||
names: craft_xml::Names::Local,
|
||||
limits: craft_xml::Limits { max_depth: MAX_LIBRARY_NESTING, max_nodes: MAX_LIBRARY_NODES as usize, ..craft_xml::Limits::DEFAULT },
|
||||
..craft_xml::Options::default()
|
||||
};
|
||||
}
|
||||
.strict();
|
||||
let doc = opts.parse(xml.as_bytes()).map_err(|e| match e {
|
||||
craft_xml::Error::TooDeep(_) => bad(cmd, format!("the variable library nests elements more than {MAX_LIBRARY_NESTING} deep")),
|
||||
_ => bad(cmd, format!("the variable library is not well-formed XML: {e}")),
|
||||
|
||||
@@ -468,6 +468,13 @@ fn malformed_docx_fails_cleanly() {
|
||||
assert!(e.contains("not a WordprocessingML document"), "{e}");
|
||||
let e = place(&mut s, "a.docx", &store(&[("word/document.xml", b"<w:document><w:body>")])).unwrap_err();
|
||||
assert!(e.contains("not well-formed XML"), "{e}");
|
||||
for xml in [
|
||||
format!(r#"<w:document xmlns:w="{W_NS}"><w:body><w:p><w:r><w:t>partial text</w:t></w:r></w:p>"#),
|
||||
document("<w:p><w:r><w:t>A&missing;B</w:t></w:r></w:p>"),
|
||||
] {
|
||||
let e = place(&mut s, "a.docx", &store(&[("word/document.xml", xml.as_bytes())])).unwrap_err();
|
||||
assert!(e.contains("not well-formed XML"), "{e}");
|
||||
}
|
||||
let e = place(&mut s, "a.docx", &store(&[("word/document.xml", document("<w:p/>").as_bytes())])).unwrap_err();
|
||||
assert!(e.contains("no text to place"), "{e}");
|
||||
// A file whose headers understate what it unpacks to, and one whose headers say it is too large.
|
||||
|
||||
@@ -2479,6 +2479,8 @@ fn malformed_variable_libraries_are_refused() {
|
||||
);
|
||||
let cases = [
|
||||
("not well-formed XML", "<variableSets><variableSet>".to_string()),
|
||||
("not well-formed XML", ok.replace("<p>x</p>", "<p>A&missing;B</p>")),
|
||||
("not well-formed XML", ok.replace("</variableSets>", "")),
|
||||
("no `variableSets` element", "<svg><variables/></svg>".to_string()),
|
||||
("declares no variables", "<variableSets><variableSet><variables/></variableSet></variableSets>".to_string()),
|
||||
("is declared twice", library(&[("Name", "textcontent"), ("Name", "textcontent")], &[])),
|
||||
|
||||
Reference in New Issue
Block a user