Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/test/test_tree7/[Content_Types].xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">
<Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml" />
<Default Extension="xml" ContentType="application/xml" />
<Default Extension="png" ContentType="image/png" />
<Override PartName="/word/theme/theme1.xml" ContentType="application/vnd.openxmlformats-officedocument.theme+xml" />
<Override PartName="/word/settings.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml" />
<Override PartName="/word/fontTable.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.fontTable+xml" />
<Override PartName="/word/webSettings.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.webSettings+xml" />
<Override PartName="/docProps/app.xml" ContentType="application/vnd.openxmlformats-officedocument.extended-properties+xml" />
<Override PartName="/docProps/core.xml" ContentType="application/vnd.openxmlformats-package.core-properties+xml" />
<Override PartName="/word/styles.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml" />
<Override PartName="/word/document2.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml" />
<Override PartName="/word/numbering.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml" />
<Override PartName="/customXml/itemProps2.xml" ContentType="application/vnd.openxmlformats-officedocument.customXmlProperties+xml" />
<Override PartName="/customXml/itemProps1.xml" ContentType="application/vnd.openxmlformats-officedocument.customXmlProperties+xml" />
<Override PartName="/customXml/itemProps3.xml" ContentType="application/vnd.openxmlformats-officedocument.customXmlProperties+xml" />
<Override PartName="/docProps/custom.xml" ContentType="application/vnd.openxmlformats-officedocument.custom-properties+xml" />
<Override PartName="/word/intelligence2.xml" ContentType="application/vnd.ms-office.intelligence2+xml" />
</Types>
10 changes: 10 additions & 0 deletions src/test/test_tree7/word/_rels/document2.xml.rels
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
<Relationship Id="rId3" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/webSettings" Target="webSettings.xml"/>
<Relationship Id="rId2" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings" Target="settings.xml"/>
<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles" Target="styles.xml"/>
<Relationship Id="rId6" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme" Target="theme/theme1.xml"/>
<Relationship Id="rId5" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable" Target="fontTable.xml"/>
<Relationship Id="rId4" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink" Target="http://www.example.com/a" TargetMode="External"/>
<Relationship Id="rId7" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink" Target="http://www.example.com/a/b" TargetMode="External"/>
</Relationships>
305 changes: 305 additions & 0 deletions src/test/test_tree7/word/document2.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,305 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<w:document xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas"
xmlns:cx="http://schemas.microsoft.com/office/drawing/2014/chartex"
xmlns:cx1="http://schemas.microsoft.com/office/drawing/2015/9/8/chartex"
xmlns:cx2="http://schemas.microsoft.com/office/drawing/2015/10/21/chartex"
xmlns:cx3="http://schemas.microsoft.com/office/drawing/2016/5/9/chartex"
xmlns:cx4="http://schemas.microsoft.com/office/drawing/2016/5/10/chartex"
xmlns:cx5="http://schemas.microsoft.com/office/drawing/2016/5/11/chartex"
xmlns:cx6="http://schemas.microsoft.com/office/drawing/2016/5/12/chartex"
xmlns:cx7="http://schemas.microsoft.com/office/drawing/2016/5/13/chartex"
xmlns:cx8="http://schemas.microsoft.com/office/drawing/2016/5/14/chartex"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:aink="http://schemas.microsoft.com/office/drawing/2016/ink"
xmlns:am3d="http://schemas.microsoft.com/office/drawing/2017/model3d"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:oel="http://schemas.microsoft.com/office/2019/extlst"
xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"
xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math"
xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing"
xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing"
xmlns:w10="urn:schemas-microsoft-com:office:word"
xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"
xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml"
xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml"
xmlns:w16cex="http://schemas.microsoft.com/office/word/2018/wordml/cex"
xmlns:w16cid="http://schemas.microsoft.com/office/word/2016/wordml/cid"
xmlns:w16="http://schemas.microsoft.com/office/word/2018/wordml"
xmlns:w16sdtdh="http://schemas.microsoft.com/office/word/2020/wordml/sdtdatahash"
xmlns:w16se="http://schemas.microsoft.com/office/word/2015/wordml/symex"
xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup"
xmlns:wpi="http://schemas.microsoft.com/office/word/2010/wordprocessingInk"
xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml"
xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape" mc:Ignorable="w14 w15 w16se w16cid w16 w16cex w16sdtdh wp14">
<w:body>
<w:p w14:paraId="30AA36DC" w14:textId="52E86AE1" w:rsidR="00146782" w:rsidRDefault="008D365C">
<w:pPr>
<w:rPr>
<w:lang w:val="en-US"/>
</w:rPr>
</w:pPr>
<w:r>
<w:rPr>
<w:lang w:val="en-US"/>
</w:rPr>
<w:t>Testing 123</w:t>
</w:r>
</w:p>
<w:p w14:paraId="288A8F5D" w14:textId="7608D659" w:rsidR="008D365C" w:rsidRDefault="008D365C">
<w:pPr>
<w:rPr>
<w:lang w:val="en-US"/>
</w:rPr>
</w:pPr>
<w:r>
<w:rPr>
<w:lang w:val="en-US"/>
</w:rPr>
<w:t>And some some more text</w:t>
</w:r>
<w:r w:rsidR="00B47895">
<w:rPr>
<w:lang w:val="en-US"/>
</w:rPr>
<w:t xml:space="preserve"> and then some</w:t>
</w:r>
</w:p>
<w:p w14:paraId="39BAD9A3" w14:textId="77777777" w:rsidR="00B47895" w:rsidRDefault="00B47895">
<w:pPr>
<w:rPr>
<w:lang w:val="en-US"/>
</w:rPr>
</w:pPr>
</w:p>
<w:p w14:paraId="2CBF7A40" w14:textId="3023CF82" w:rsidR="00B47895" w:rsidRDefault="00B47895">
<w:pPr>
<w:rPr>
<w:lang w:val="en-US"/>
</w:rPr>
</w:pPr>
<w:r>
<w:rPr>
<w:lang w:val="en-US"/>
</w:rPr>
<w:t>Something here</w:t>
</w:r>
</w:p>
<w:p w14:paraId="6EBBCD16" w14:textId="77777777" w:rsidR="00B47895" w:rsidRDefault="00B47895">
<w:pPr>
<w:rPr>
<w:lang w:val="en-US"/>
</w:rPr>
</w:pPr>
</w:p>
<w:tbl>
<w:tblPr>
<w:tblStyle w:val="TableGrid"/>
<w:tblW w:w="0" w:type="auto"/>
<w:tblLook w:val="04A0" w:firstRow="1" w:lastRow="0" w:firstColumn="1" w:lastColumn="0" w:noHBand="0" w:noVBand="1"/>
</w:tblPr>
<w:tblGrid>
<w:gridCol w:w="3005"/>
<w:gridCol w:w="3005"/>
<w:gridCol w:w="3006"/>
</w:tblGrid>
<w:tr w:rsidR="00B47895" w14:paraId="4B71DB47" w14:textId="77777777" w:rsidTr="00B47895">
<w:tc>
<w:tcPr>
<w:tcW w:w="3005" w:type="dxa"/>
</w:tcPr>
<w:p w14:paraId="5EB79979" w14:textId="46409BE4" w:rsidR="00B47895" w:rsidRDefault="00B47895">
<w:pPr>
<w:rPr>
<w:lang w:val="en-US"/>
</w:rPr>
</w:pPr>
<w:r>
<w:rPr>
<w:lang w:val="en-US"/>
</w:rPr>
<w:t>Blah</w:t>
</w:r>
</w:p>
</w:tc>
<w:tc>
<w:tcPr>
<w:tcW w:w="3005" w:type="dxa"/>
</w:tcPr>
<w:p w14:paraId="4487AD6B" w14:textId="5830B00E" w:rsidR="00B47895" w:rsidRDefault="00B47895">
<w:pPr>
<w:rPr>
<w:lang w:val="en-US"/>
</w:rPr>
</w:pPr>
<w:r>
<w:rPr>
<w:lang w:val="en-US"/>
</w:rPr>
<w:t>some</w:t>
</w:r>
</w:p>
</w:tc>
<w:tc>
<w:tcPr>
<w:tcW w:w="3006" w:type="dxa"/>
</w:tcPr>
<w:p w14:paraId="2414C261" w14:textId="57AF738E" w:rsidR="00B47895" w:rsidRDefault="00B47895">
<w:pPr>
<w:rPr>
<w:lang w:val="en-US"/>
</w:rPr>
</w:pPr>
<w:r>
<w:rPr>
<w:lang w:val="en-US"/>
</w:rPr>
<w:t>None</w:t>
</w:r>
</w:p>
</w:tc>
</w:tr>
<w:tr w:rsidR="00B47895" w14:paraId="75A8A72B" w14:textId="77777777" w:rsidTr="00B47895">
<w:tc>
<w:tcPr>
<w:tcW w:w="3005" w:type="dxa"/>
</w:tcPr>
<w:p w14:paraId="69F61D0A" w14:textId="1DE2D5C9" w:rsidR="00B47895" w:rsidRDefault="00B47895">
<w:pPr>
<w:rPr>
<w:lang w:val="en-US"/>
</w:rPr>
</w:pPr>
<w:r>
<w:rPr>
<w:lang w:val="en-US"/>
</w:rPr>
<w:t xml:space="preserve">Some </w:t>
</w:r>
<w:proofErr w:type="spellStart"/>
<w:r>
<w:rPr>
<w:lang w:val="en-US"/>
</w:rPr>
<w:t>some</w:t>
</w:r>
<w:proofErr w:type="spellEnd"/>
<w:r>
<w:rPr>
<w:lang w:val="en-US"/>
</w:rPr>
<w:t xml:space="preserve"></w:t>
</w:r>
<w:proofErr w:type="spellStart"/>
<w:r>
<w:rPr>
<w:lang w:val="en-US"/>
</w:rPr>
<w:t>some</w:t>
</w:r>
<w:proofErr w:type="spellEnd"/>
</w:p>
</w:tc>
<w:tc>
<w:tcPr>
<w:tcW w:w="3005" w:type="dxa"/>
</w:tcPr>
<w:p w14:paraId="21C4F834" w14:textId="34C11663" w:rsidR="00B47895" w:rsidRDefault="00B47895">
<w:pPr>
<w:rPr>
<w:lang w:val="en-US"/>
</w:rPr>
</w:pPr>
<w:r>
<w:rPr>
<w:lang w:val="en-US"/>
</w:rPr>
<w:t>hello</w:t>
</w:r>
</w:p>
</w:tc>
<w:tc>
<w:tcPr>
<w:tcW w:w="3006" w:type="dxa"/>
</w:tcPr>
<w:p w14:paraId="1C72A820" w14:textId="77777777" w:rsidR="00B47895" w:rsidRDefault="00B47895">
<w:pPr>
<w:rPr>
<w:lang w:val="en-US"/>
</w:rPr>
</w:pPr>
</w:p>
</w:tc>
</w:tr>
</w:tbl>
<w:p w14:paraId="661AA0A6" w14:textId="77777777" w:rsidR="00B47895" w:rsidRDefault="00B47895">
<w:pPr>
<w:rPr>
<w:lang w:val="en-US"/>
</w:rPr>
</w:pPr>
</w:p>
<w:p w14:paraId="684CE415" w14:textId="562692B0" w:rsidR="00241272" w:rsidRDefault="00241272">
<w:pPr>
<w:rPr>
<w:lang w:val="en-US"/>
</w:rPr>
</w:pPr>
<w:r>
<w:rPr>
<w:lang w:val="en-US"/>
</w:rPr>
<w:t xml:space="preserve">Here’s a hyperlink: </w:t>
</w:r>
<w:hyperlink r:id="rId4" w:history="1">
<w:r w:rsidRPr="00241272">
<w:rPr>
<w:rStyle w:val="Hyperlink"/>
<w:lang w:val="en-US"/>
</w:rPr>
<w:t>link</w:t>
</w:r>
</w:hyperlink>
</w:p>
<w:p w14:paraId="38F5C028" w14:textId="77777777" w:rsidR="00241272" w:rsidRDefault="00241272">
<w:pPr>
<w:rPr>
<w:lang w:val="en-US"/>
</w:rPr>
</w:pPr>
</w:p>
<w:p w14:paraId="2297FEA1" w14:textId="418C909A" w:rsidR="00241272" w:rsidRPr="008D365C" w:rsidRDefault="00241272">
<w:pPr>
<w:rPr>
<w:lang w:val="en-US"/>
</w:rPr>
</w:pPr>
<w:r>
<w:rPr>
<w:lang w:val="en-US"/>
</w:rPr>
<w:t xml:space="preserve">And here’s just some text: </w:t>
</w:r>
<w:proofErr w:type="gramStart"/>
<w:r>
<w:rPr>
<w:lang w:val="en-US"/>
</w:rPr>
<w:t>www.example.com/a</w:t>
</w:r>
<w:r>
<w:rPr>
<w:lang w:val="en-US"/>
</w:rPr>
<w:t>www.example.com/a/b</w:t>
</w:r>
<w:proofErr w:type="gramEnd"/>
</w:p>
<w:sectPr w:rsidR="00241272" w:rsidRPr="008D365C">
<w:pgSz w:w="11906" w:h="16838"/>
<w:pgMar w:top="1440" w:right="1440" w:bottom="1440" w:left="1440" w:header="708" w:footer="708" w:gutter="0"/>
<w:cols w:space="708"/>
<w:docGrid w:linePitch="360"/>
</w:sectPr>
</w:body>
</w:document>
30 changes: 30 additions & 0 deletions src/xml_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1210,6 +1210,36 @@ mod tests {
Ok(())
}

#[test]
fn test_replace_hyperlink2() -> io::Result<()> {
let orgdir = "./src/test/test_tree7";
let testdir = testdir!();

copy_dir_all(orgdir, &testdir)?;

let before_doc = fs::read_to_string("./src/test/test_tree7/word/document2.xml")?;
let before = fs::read_to_string("./src/test/test_tree7/word/_rels/document2.xml.rels")?;

assert!(before.contains("Target=\"http://www.example.com/a\""), "Precondition");
assert!(before_doc.contains(">www.example.com/a<"), "Precondition");
assert!(before.contains("Target=\"http://www.example.com/a/b\""), "Precondition");
assert!(before_doc.contains(">www.example.com/a/b<"), "Precondition");

XMLUtil::replace_rel_attr(&testdir.to_string_lossy(), "my-source.docx",
"www.example.com/a$", "www.example.com/a/",
&Some(&testdir.join("output-2.docx").to_string_lossy()));

let after_doc = fs::read_to_string(testdir.join("word/document2.xml"))?;
let after = fs::read_to_string(testdir.join("word/_rels/document2.xml.rels"))?;

assert!(after.contains("Target=\"http://www.example.com/a/\""));
assert!(after_doc.contains(">www.example.com/a<"), "Should not have changed the document text");
assert!(after.contains("Target=\"http://www.example.com/a/b\""), "Should not have changed this link");
assert!(after_doc.contains(">www.example.com/a/b<"), "Should not have changed the document text");

Ok(())
}

#[test]
fn test_replace_both() -> io::Result<()> {
let orgdir = "./src/test/test_tree3";
Expand Down