diff --git a/pydocx/openxml/wordprocessing/simple_field.py b/pydocx/openxml/wordprocessing/simple_field.py index 116d4b0c..f34fe8e3 100644 --- a/pydocx/openxml/wordprocessing/simple_field.py +++ b/pydocx/openxml/wordprocessing/simple_field.py @@ -38,6 +38,8 @@ def _parse_instr_arg_string_to_args(self, arg_string): return re.findall(r'\s*(?:"([^"]+)"|([^\s]+))+', arg_string) def parse_instr(self): + if self.instr is None: + return m = self._parse_instr_into_field_type_and_arg_string() if not m: return diff --git a/tests/export/html/test_simple_field.py b/tests/export/html/test_simple_field.py index c16aa8b5..75170097 100644 --- a/tests/export/html/test_simple_field.py +++ b/tests/export/html/test_simple_field.py @@ -202,6 +202,10 @@ def parse(self, instr): field = SimpleField(instr=instr) return field.parse_instr() + def test_with_None_instr_returns_None(self): + result = self.parse(None) + self.assertEqual(result, None) + def test_with_blank_instr_returns_None(self): result = self.parse('') self.assertEqual(result, None)