From 8e95f5abce943c9d2bf8dc859d628085beb15901 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Wed, 9 Mar 2022 21:00:46 +0000 Subject: Ignore w:u elements when w:val is missing --- NEWS | 4 ++++ mammoth/docx/body_xml.py | 2 +- tests/docx/body_xml_tests.py | 4 ++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/NEWS b/NEWS index 388a2a0..a30c011 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,7 @@ +# 1.4.19 + +* Ignore w:u elements when w:val is missing. + # 1.4.18 * Emit warning instead of throwing exception when image file cannot be found for diff --git a/mammoth/docx/body_xml.py b/mammoth/docx/body_xml.py index 8d727a5..c11e9e5 100644 --- a/mammoth/docx/body_xml.py +++ b/mammoth/docx/body_xml.py @@ -127,7 +127,7 @@ def _create_reader(numbering, content_types, relationships, styles, docx_file, f return element and element.attributes.get("w:val") not in ["false", "0"] def read_underline_element(element): - return element and element.attributes.get("w:val") not in ["false", "0", "none"] + return element and element.attributes.get("w:val") not in [None, "false", "0", "none"] def paragraph(element): properties = element.find_child_or_null("w:pPr") diff --git a/tests/docx/body_xml_tests.py b/tests/docx/body_xml_tests.py index e0328fb..d7f5509 100644 --- a/tests/docx/body_xml_tests.py +++ b/tests/docx/body_xml_tests.py @@ -275,9 +275,9 @@ class RunTests(object): assert_equal(False, run.is_underline) @istest - def run_is_underlined_if_underline_element_is_present_without_val_attribute(self): + def run_is_not_underlined_if_underline_element_is_present_without_val_attribute(self): run = self._read_run_with_properties([xml_element("w:u")]) - assert_equal(True, run.is_underline) + assert_equal(False, run.is_underline) @istest def run_is_not_underlined_if_underline_element_is_present_and_val_is_false(self): -- cgit v1.2.3