summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2026-03-12 21:05:37 +0000
committerMichael Williamson <mike@zwobble.org>2026-03-12 21:05:37 +0000
commit6cfbe0b8952b809bb1a3564041c8155405336167 (patch)
treeb4f6b75881e90aa9a1258ed0f0fe3c7d089a776f /test
parent5b8d20f1cdca33a08cd0cb72af5b13c22653cea3 (diff)
Handle hyperlink complex fields with unquoted hrefs
Diffstat (limited to 'test')
-rw-r--r--test/docx/body-reader.tests.js62
1 files changed, 58 insertions, 4 deletions
diff --git a/test/docx/body-reader.tests.js b/test/docx/body-reader.tests.js
index dee38a5..26c57e2 100644
--- a/test/docx/body-reader.tests.js
+++ b/test/docx/body-reader.tests.js
@@ -332,11 +332,13 @@ test("complex fields", (function() {
assert.deepEqual(instrText, []);
},
- "runs in a complex field for hyperlink without switch are read as external hyperlinks": function() {
+ "runs in a complex field for hyperlink without switch with quoted target are read as external hyperlinks": function() {
var hyperlinkRunXml = runOfText("this is a hyperlink");
var paragraphXml = new XmlElement("w:p", {}, [
beginXml,
- hyperlinkInstrText,
+ new XmlElement("w:instrText", {}, [
+ xml.text(' HYPERLINK "http://example.com"')
+ ]),
separateXml,
hyperlinkRunXml,
endXml
@@ -347,7 +349,7 @@ test("complex fields", (function() {
isEmptyRun,
isEmptyHyperlinkedRun,
isHyperlinkedRun({
- href: uri,
+ href: "http://example.com",
children: contains(
isText("this is a hyperlink")
)
@@ -356,7 +358,33 @@ test("complex fields", (function() {
));
},
- "runs in a complex field for hyperlink with l switch are read as internal hyperlinks": function() {
+ "runs in a complex field for hyperlink without switch with unquoted target are read as external hyperlinks": function() {
+ var hyperlinkRunXml = runOfText("this is a hyperlink");
+ var paragraphXml = new XmlElement("w:p", {}, [
+ beginXml,
+ new XmlElement("w:instrText", {}, [
+ xml.text(' HYPERLINK http://example.com')
+ ]),
+ separateXml,
+ hyperlinkRunXml,
+ endXml
+ ]);
+ var paragraph = readXmlElementValue(paragraphXml);
+
+ assertThat(paragraph.children, contains(
+ isEmptyRun,
+ isEmptyHyperlinkedRun,
+ isHyperlinkedRun({
+ href: "http://example.com",
+ children: contains(
+ isText("this is a hyperlink")
+ )
+ }),
+ isEmptyRun
+ ));
+ },
+
+ "runs in a complex field for hyperlink with l switch with quoted target are read as internal hyperlinks": function() {
var hyperlinkRunXml = runOfText("this is a hyperlink");
var paragraphXml = new XmlElement("w:p", {}, [
beginXml,
@@ -382,6 +410,32 @@ test("complex fields", (function() {
));
},
+ "runs in a complex field for hyperlink with l switch with unquoted target are read as internal hyperlinks": function() {
+ var hyperlinkRunXml = runOfText("this is a hyperlink");
+ var paragraphXml = new XmlElement("w:p", {}, [
+ beginXml,
+ new XmlElement("w:instrText", {}, [
+ xml.text(' HYPERLINK \\l InternalLink')
+ ]),
+ separateXml,
+ hyperlinkRunXml,
+ endXml
+ ]);
+ var paragraph = readXmlElementValue(paragraphXml);
+
+ assertThat(paragraph.children, contains(
+ isEmptyRun,
+ isEmptyHyperlinkedRun,
+ isHyperlinkedRun({
+ anchor: "InternalLink",
+ children: contains(
+ isText("this is a hyperlink")
+ )
+ }),
+ isEmptyRun
+ ));
+ },
+
"runs after a complex field for hyperlinks are not read as hyperlinks": function() {
var afterEndXml = runOfText("this will not be a hyperlink");
var paragraphXml = new XmlElement("w:p", {}, [