mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-14 22:42:46 +00:00
fix(docx): preserve case-insensitive main part fallback
This commit is contained in:
1 parent
fbbebecf27
commit
7f59e8f3f5
2 files changed
+21
-11
No files matched your search
@@ -204,7 +204,7 @@ fn read_opened_in(pkg: &Package, chunks: ChunkState) -> Result<(Document, usize,
|
||||
// those files when a producer omitted the document relationship; the bounded package
|
||||
// reader still applies the same entry and XML limits. An explicit usable relationship
|
||||
// always wins, including when it points outside the conventional `word/` paths.
|
||||
if main != "word/document.xml" {
|
||||
if !main.eq_ignore_ascii_case("word/document.xml") {
|
||||
return None;
|
||||
}
|
||||
let fallback = match t {
|
||||
|
||||
@@ -81,15 +81,25 @@ fn conventional_styles_and_numbering_parts_without_relationships_are_read() {
|
||||
let numbering = format!(
|
||||
r#"<w:numbering xmlns:w="{W}"><w:abstractNum w:abstractNumId="0"><w:lvl w:ilvl="0"><w:numFmt w:val="decimal"/><w:lvlText w:val="%1."/></w:lvl></w:abstractNum><w:num w:numId="7"><w:abstractNumId w:val="0"/></w:num></w:numbering>"#
|
||||
);
|
||||
let mut zw = zip::ZipWriter::new(std::io::Cursor::new(Vec::new()));
|
||||
for (name, body) in [("word/document.xml", doc.as_str()), ("word/styles.xml", styles.as_str()), ("word/numbering.xml", numbering.as_str())] {
|
||||
zw.start_file(name, zip::write::SimpleFileOptions::default()).unwrap();
|
||||
zw.write_all(body.as_bytes()).unwrap();
|
||||
for main_path in ["word/document.xml", "WORD/DOCUMENT.XML"] {
|
||||
let root = format!(
|
||||
r#"<?xml version="1.0" encoding="UTF-8"?><Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="{main_path}"/></Relationships>"#
|
||||
);
|
||||
let mut zw = zip::ZipWriter::new(std::io::Cursor::new(Vec::new()));
|
||||
for (name, body) in [
|
||||
("_rels/.rels", root.as_str()),
|
||||
(main_path, doc.as_str()),
|
||||
("word/styles.xml", styles.as_str()),
|
||||
("word/numbering.xml", numbering.as_str()),
|
||||
] {
|
||||
zw.start_file(name, zip::write::SimpleFileOptions::default()).unwrap();
|
||||
zw.write_all(body.as_bytes()).unwrap();
|
||||
}
|
||||
let d = craft_docx::read(&zw.finish().unwrap().into_inner()).unwrap();
|
||||
assert!(d.styles.styles.iter().any(|style| style.id == "Body"));
|
||||
let Some(Block::Para(p)) = d.body.first().map(|b| &**b) else { panic!("a body paragraph") };
|
||||
assert_eq!(p.props.style.as_deref(), Some("Body"));
|
||||
assert_eq!(p.props.numbering.map(|n| (n.num, n.level)), Some((7, 0)));
|
||||
assert!(d.numbering.level(7, 0).is_some());
|
||||
}
|
||||
let d = craft_docx::read(&zw.finish().unwrap().into_inner()).unwrap();
|
||||
assert!(d.styles.styles.iter().any(|style| style.id == "Body"));
|
||||
let Some(Block::Para(p)) = d.body.first().map(|b| &**b) else { panic!("a body paragraph") };
|
||||
assert_eq!(p.props.style.as_deref(), Some("Body"));
|
||||
assert_eq!(p.props.numbering.map(|n| (n.num, n.level)), Some((7, 0)));
|
||||
assert!(d.numbering.level(7, 0).is_some());
|
||||
}
|
||||
Reference in new issue
Block a user