diff options
| author | Michael Williamson <mike@zwobble.org> | 2017-04-22 15:46:01 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2017-04-22 15:46:42 +0100 |
| commit | 53e02510f14a4ed91d1ef5f194be564a83e05fb4 (patch) | |
| tree | 5f09485c80ce9cefc5a447cbf3f73d3ea074473e | |
| parent | cedd2d6d5401b78030318f9e64f684d6ea86085d (diff) | |
Handle complex fields that do not have a "separate" fldChar
| -rw-r--r-- | NEWS | 4 | ||||
| -rw-r--r-- | lib/docx/body-reader.js | 6 | ||||
| -rw-r--r-- | test/docx/body-reader.tests.js | 27 |
3 files changed, 36 insertions, 1 deletions
@@ -1,3 +1,7 @@ +# 1.3.6 + +* Handle complex fields that do not have a "separate" fldChar. + # 1.3.5 * Add transforms.run. diff --git a/lib/docx/body-reader.js b/lib/docx/body-reader.js index 0bdd2a0..dd76c5c 100644 --- a/lib/docx/body-reader.js +++ b/lib/docx/body-reader.js @@ -99,15 +99,19 @@ function BodyReader(options) { return elementResultWithMessages({styleId: styleId, name: name}, messages); } + var unknownComplexField = {type: "unknown"}; + function readFldChar(element) { var type = element.attributes["w:fldCharType"]; if (type === "begin") { + complexFieldStack.push(unknownComplexField); currentInstrText = []; } else if (type === "end") { complexFieldStack.pop(); } else if (type === "separate") { var href = parseHyperlinkFieldCode(currentInstrText.join('')); - var complexField = href === null ? {type: "unknown"} : {type: "hyperlink", href: href}; + var complexField = href === null ? unknownComplexField : {type: "hyperlink", href: href}; + complexFieldStack.pop(); complexFieldStack.push(complexField); } return emptyResult(); diff --git a/test/docx/body-reader.tests.js b/test/docx/body-reader.tests.js index 1b9a392..ffcc7d8 100644 --- a/test/docx/body-reader.tests.js +++ b/test/docx/body-reader.tests.js @@ -309,6 +309,33 @@ test("complex fields", (function() { isEmptyHyperlinkedRun, isEmptyRun )); + }, + + "field without separate element is ignored": function() { + var hyperlinkRunXml = runOfText("this is a hyperlink"); + var paragraphXml = new XmlElement("w:p", {}, [ + beginXml, + hyperlinkInstrText, + separateXml, + beginXml, + endXml, + hyperlinkRunXml, + endXml + ]); + var paragraph = readXmlElementValue(paragraphXml); + + assertThat(paragraph.children, contains( + isEmptyRun, + isEmptyHyperlinkedRun, + isEmptyHyperlinkedRun, + isEmptyHyperlinkedRun, + isHyperlinkedRun({ + children: contains( + isText("this is a hyperlink") + ) + }), + isEmptyRun + )); } }; })()); |
