aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2026-03-12 21:24:22 +0000
committerMichael Williamson <mike@zwobble.org>2026-03-12 21:24:22 +0000
commit271b5f05d16576d479530663657c31ef37f1391b (patch)
tree55fe0e95f5ece9c79447b62b705caa237390458d /src/test
parent076de3f0567b44e349f7f7af99e5c4ad215646a2 (diff)
Handle hyperlink complex fields with unquoted hrefs
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/org/zwobble/mammoth/tests/docx/BodyXmlTests.java68
1 files changed, 60 insertions, 8 deletions
diff --git a/src/test/java/org/zwobble/mammoth/tests/docx/BodyXmlTests.java b/src/test/java/org/zwobble/mammoth/tests/docx/BodyXmlTests.java
index 71d8627..135ad54 100644
--- a/src/test/java/org/zwobble/mammoth/tests/docx/BodyXmlTests.java
+++ b/src/test/java/org/zwobble/mammoth/tests/docx/BodyXmlTests.java
@@ -374,13 +374,14 @@ public class BodyXmlTests {
}
@Test
- public void runsInAComplexFieldForHyperlinksWithoutSwitchAreReadAsExternalHyperlinks() {
- XmlElement hyperlinkRunXml = runXml("this is a hyperlink");
+ public void runsInAComplexFieldForHyperlinksWithoutSwitchWithQuotedLocationAreReadAsExternalHyperlinks() {
XmlElement element = paragraphXml(list(
BEGIN_COMPLEX_FIELD,
- HYPERLINK_INSTRTEXT,
+ element("w:instrText", list(
+ XmlNodes.text(" HYPERLINK \"http://example.com\"")
+ )),
SEPARATE_COMPLEX_FIELD,
- hyperlinkRunXml,
+ runXml("this is a hyperlink"),
END_COMPLEX_FIELD
));
DocumentElement paragraph = readSuccess(bodyReader(), element);
@@ -389,7 +390,7 @@ public class BodyXmlTests {
isEmptyRun(),
isEmptyHyperlinkedRun(),
isHyperlinkedRun(
- hasHref(URI),
+ hasHref("http://example.com"),
hasChildren(
isTextElement("this is a hyperlink")
)
@@ -399,15 +400,66 @@ public class BodyXmlTests {
}
@Test
- public void runsInAComplexFieldForHyperlinksWithLSwitchAreReadAsInternalHyperlinks() {
- XmlElement hyperlinkRunXml = runXml("this is a hyperlink");
+ public void runsInAComplexFieldForHyperlinksWithoutSwitchWithUnquotedLocationAreReadAsExternalHyperlinks() {
+ XmlElement element = paragraphXml(list(
+ BEGIN_COMPLEX_FIELD,
+ element("w:instrText", list(
+ XmlNodes.text(" HYPERLINK http://example.com")
+ )),
+ SEPARATE_COMPLEX_FIELD,
+ runXml("this is a hyperlink"),
+ END_COMPLEX_FIELD
+ ));
+ DocumentElement paragraph = readSuccess(bodyReader(), element);
+
+ assertThat(paragraph, isParagraph(hasChildren(
+ isEmptyRun(),
+ isEmptyHyperlinkedRun(),
+ isHyperlinkedRun(
+ hasHref("http://example.com"),
+ hasChildren(
+ isTextElement("this is a hyperlink")
+ )
+ ),
+ isEmptyRun()
+ )));
+ }
+
+ @Test
+ public void runsInAComplexFieldForHyperlinksWithLSwitchWithQuotedLocationAreReadAsInternalHyperlinks() {
XmlElement element = paragraphXml(list(
BEGIN_COMPLEX_FIELD,
element("w:instrText", list(
XmlNodes.text(" HYPERLINK \\l \"InternalLink\"")
)),
SEPARATE_COMPLEX_FIELD,
- hyperlinkRunXml,
+ runXml("this is a hyperlink"),
+ END_COMPLEX_FIELD
+ ));
+ DocumentElement paragraph = readSuccess(bodyReader(), element);
+
+ assertThat(paragraph, isParagraph(hasChildren(
+ isEmptyRun(),
+ isEmptyHyperlinkedRun(),
+ isHyperlinkedRun(
+ hasAnchor("InternalLink"),
+ hasChildren(
+ isTextElement("this is a hyperlink")
+ )
+ ),
+ isEmptyRun()
+ )));
+ }
+
+ @Test
+ public void runsInAComplexFieldForHyperlinksWithLSwitchWithUnquotedLocationAreReadAsInternalHyperlinks() {
+ XmlElement element = paragraphXml(list(
+ BEGIN_COMPLEX_FIELD,
+ element("w:instrText", list(
+ XmlNodes.text(" HYPERLINK \\l InternalLink")
+ )),
+ SEPARATE_COMPLEX_FIELD,
+ runXml("this is a hyperlink"),
END_COMPLEX_FIELD
));
DocumentElement paragraph = readSuccess(bodyReader(), element);