diff options
| -rw-r--r-- | NEWS | 4 | ||||
| -rw-r--r-- | mammoth/docx/numbering_xml.py | 6 | ||||
| -rw-r--r-- | tests/docx/numbering_xml_tests.py | 13 |
3 files changed, 21 insertions, 2 deletions
@@ -1,3 +1,7 @@ +# 1.4.16 + +* Handle w:num with invalid w:abstractNumId. + # 1.4.15 * Convert symbols in supported fonts to corresponding Unicode characters. diff --git a/mammoth/docx/numbering_xml.py b/mammoth/docx/numbering_xml.py index e1ea0b4..7f7bf0e 100644 --- a/mammoth/docx/numbering_xml.py +++ b/mammoth/docx/numbering_xml.py @@ -91,8 +91,10 @@ class Numbering(object): if num is None: return None else: - abstract_num = self._abstract_nums[num.abstract_num_id] - if abstract_num.num_style_link is None: + abstract_num = self._abstract_nums.get(num.abstract_num_id) + if abstract_num is None: + return None + elif abstract_num.num_style_link is None: return self._to_numbering_level(abstract_num.levels.get(level)) else: style = self._styles.find_numbering_style_by_id(abstract_num.num_style_link) diff --git a/tests/docx/numbering_xml_tests.py b/tests/docx/numbering_xml_tests.py index 812610e..6c1d843 100644 --- a/tests/docx/numbering_xml_tests.py +++ b/tests/docx/numbering_xml_tests.py @@ -51,6 +51,19 @@ def find_level_returns_none_if_level_cannot_be_found(): @istest +def num_referencing_non_existent_abstract_num_is_ignored(): + element = xml_element("w:numbering", {}, [ + xml_element("w:num", {"w:numId": "47"}, [ + xml_element("w:abstractNumId", {"w:val": "42"}) + ]) + ]) + + numbering = _read_numbering_xml_element(element) + + assert_equal(None, numbering.find_level("47", "0")) + + +@istest def when_abstract_num_has_num_style_link_then_style_is_used_to_find_num(): numbering = _read_numbering_xml_element( xml_element("w:numbering", {}, [ |
