aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2021-05-11 22:24:27 +0100
committerMichael Williamson <mike@zwobble.org>2021-05-11 22:24:27 +0100
commit9420bb9bea5b44f475d32e12b2e50e96a888d900 (patch)
tree03be26b2232cb70a3510f2854e83f50c7865a182
parentc2d79f884373c93f1bd222f86c8057354837709a (diff)
Handle w:num with invalid w:abstractNumId
-rw-r--r--NEWS4
-rw-r--r--lib/docx/numbering-xml.js4
-rw-r--r--test/docx/numbering-xml.tests.js13
3 files changed, 20 insertions, 1 deletions
diff --git a/NEWS b/NEWS
index 937a043..2313c34 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,7 @@
+# 1.4.17
+
+* Handle w:num with invalid w:abstractNumId
+
# 1.4.16
* Convert symbols in supported fonts to corresponding Unicode characters.
diff --git a/lib/docx/numbering-xml.js b/lib/docx/numbering-xml.js
index 64c4210..832e414 100644
--- a/lib/docx/numbering-xml.js
+++ b/lib/docx/numbering-xml.js
@@ -20,7 +20,9 @@ function Numbering(nums, abstractNums, styles) {
var num = nums[numId];
if (num) {
var abstractNum = abstractNums[num.abstractNumId];
- if (abstractNum.numStyleLink == null) {
+ if (!abstractNum) {
+ return null;
+ } else if (abstractNum.numStyleLink == null) {
return abstractNums[num.abstractNumId].levels[level];
} else {
var style = styles.findNumberingStyleById(abstractNum.numStyleLink);
diff --git a/test/docx/numbering-xml.tests.js b/test/docx/numbering-xml.tests.js
index 1eefd37..1a20ab0 100644
--- a/test/docx/numbering-xml.tests.js
+++ b/test/docx/numbering-xml.tests.js
@@ -33,6 +33,19 @@ test('w:num element inherits levels from w:abstractNum', function() {
});
+test('w:num element referencing non-existent w:abstractNumId is ignored', function() {
+ var numbering = readNumberingXml(
+ new XmlElement("w:numbering", {}, [
+ new XmlElement("w:num", {"w:numId": "47"}, [
+ new XmlElement("w:abstractNumId", {"w:val": "42"})
+ ])
+ ]),
+ {styles: stylesReader.defaultStyles}
+ );
+ duck.assertThat(numbering.findLevel("47", "0"), duck.equalTo(null));
+});
+
+
test('when w:abstractNum has w:numStyleLink then style is used to find w:num', function() {
var numbering = readNumberingXml(
new XmlElement("w:numbering", {}, [