From 2e819654db985bf8a7e7ed76e0a43dc2f46eec8d Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Mon, 23 Jan 2017 20:37:05 +0000 Subject: Handle base-relative target URIs --- .../org/zwobble/mammoth/tests/MammothTests.java | 9 +++++++- .../java/org/zwobble/mammoth/tests/docx/Uris.java | 25 +++++++++++++++++++++ .../tiny-picture-target-base-relative.docx | Bin 0 -> 10881 bytes 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 src/test/java/org/zwobble/mammoth/tests/docx/Uris.java create mode 100644 src/test/resources/test-data/tiny-picture-target-base-relative.docx (limited to 'src/test') diff --git a/src/test/java/org/zwobble/mammoth/tests/MammothTests.java b/src/test/java/org/zwobble/mammoth/tests/MammothTests.java index d7a2b66..ac81c76 100644 --- a/src/test/java/org/zwobble/mammoth/tests/MammothTests.java +++ b/src/test/java/org/zwobble/mammoth/tests/MammothTests.java @@ -69,12 +69,19 @@ public class MammothTests { } @Test - public void inlineImagesAreIncludedInOutput() throws IOException { + public void inlineImagesReferencedByPathRelativeToPartAreIncludedInOutput() throws IOException { assertThat( convertToHtml("tiny-picture.docx"), isSuccess("

")); } + @Test + public void inlineImagesReferencedByPathRelativeToBaseAreIncludedInOutput() throws IOException { + assertThat( + convertToHtml("tiny-picture-target-base-relative.docx"), + isSuccess("

")); + } + @Test public void imagesStoredOutsideOfDocumentAreIncludedInOutput() throws IOException { Path tempDirectory = Files.createTempDirectory("mammoth-"); diff --git a/src/test/java/org/zwobble/mammoth/tests/docx/Uris.java b/src/test/java/org/zwobble/mammoth/tests/docx/Uris.java new file mode 100644 index 0000000..36d4bcb --- /dev/null +++ b/src/test/java/org/zwobble/mammoth/tests/docx/Uris.java @@ -0,0 +1,25 @@ +package org.zwobble.mammoth.tests.docx; + +import org.junit.Test; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; +import static org.zwobble.mammoth.internal.docx.Uris.uriToZipEntryName; + +public class Uris { + @Test + public void whenPathDoesNotHaveLeadingSlashThenPathIsResolvedRelativeToBase() { + assertThat( + uriToZipEntryName("one/two", "three/four"), + equalTo("one/two/three/four") + ); + } + + @Test + public void whenPathHasLeadingSlashThenBaseIsIgnored() { + assertThat( + uriToZipEntryName("one/two", "/three/four"), + equalTo("three/four") + ); + } +} diff --git a/src/test/resources/test-data/tiny-picture-target-base-relative.docx b/src/test/resources/test-data/tiny-picture-target-base-relative.docx new file mode 100644 index 0000000..1d61988 Binary files /dev/null and b/src/test/resources/test-data/tiny-picture-target-base-relative.docx differ -- cgit v1.2.3