summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2017-05-30 11:34:41 +0100
committerMichael Williamson <mike@zwobble.org>2017-05-30 11:34:41 +0100
commitb5eebcb970dca395f4e199fc26cc6971798a951d (patch)
treeee338b09a49666519cd733c1a6766eee6e734fc6
parentf772284b08698a47430549f18abc6e004ac06fb6 (diff)
Set target frame to None when empty string
-rw-r--r--mammoth/docx/body_xml.py2
-rw-r--r--tests/docx/body_xml_tests.py11
2 files changed, 12 insertions, 1 deletions
diff --git a/mammoth/docx/body_xml.py b/mammoth/docx/body_xml.py
index 3e3e027..a087191 100644
--- a/mammoth/docx/body_xml.py
+++ b/mammoth/docx/body_xml.py
@@ -297,7 +297,7 @@ def _create_reader(numbering, content_types, relationships, styles, docx_file, f
def hyperlink(element):
relationship_id = element.attributes.get("r:id")
anchor = element.attributes.get("w:anchor")
- target_frame = element.attributes.get("w:tgtFrame")
+ target_frame = element.attributes.get("w:tgtFrame") or None
children_result = _read_xml_elements(element.children)
def create(**kwargs):
diff --git a/tests/docx/body_xml_tests.py b/tests/docx/body_xml_tests.py
index 2c418d2..98e93ed 100644
--- a/tests/docx/body_xml_tests.py
+++ b/tests/docx/body_xml_tests.py
@@ -683,6 +683,17 @@ class HyperlinkTests(object):
_read_and_get_document_xml_element(element),
is_hyperlink(target_frame="_blank"),
)
+
+ @istest
+ def empty_target_frame_is_ignored(self):
+ element = xml_element("w:hyperlink", {
+ "w:anchor": "start",
+ "w:tgtFrame": "",
+ })
+ assert_that(
+ _read_and_get_document_xml_element(element),
+ is_hyperlink(target_frame=None),
+ )
@istest