diff options
| author | Michael Williamson <mike@zwobble.org> | 2026-09-12 09:57:20 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2026-09-12 09:57:20 +0100 |
| commit | d9678f1c64103c2062f30dc0dd66a5679ef0cf01 (patch) | |
| tree | 9b69ff684284da6ba80ac70f463984f58eebfbc4 /mammoth | |
| parent | fd2f9f53fce3f7d07f1f6152e983b01a445c3049 (diff) | |
Handle missing complex field start characters
Diffstat (limited to 'mammoth')
| -rw-r--r-- | mammoth/docx/body_xml.py | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/mammoth/docx/body_xml.py b/mammoth/docx/body_xml.py index 2a1ffaf..4abf7f3 100644 --- a/mammoth/docx/body_xml.py +++ b/mammoth/docx/body_xml.py @@ -203,6 +203,11 @@ def _create_reader(numbering, content_types, relationships, styles, docx_file, f del current_instr_text[:] elif fld_char_type == "end": + if len(complex_field_stack) == 0: + return _empty_result_with_message(results.warning( + "ignoring complex field end character without corresponding start character", + )) + complex_field = complex_field_stack.pop() if isinstance(complex_field, complex_fields.Begin): complex_field = parse_current_instr_text(complex_field) @@ -211,6 +216,11 @@ def _create_reader(numbering, content_types, relationships, styles, docx_file, f return _success(documents.checkbox(checked=complex_field.checked)) elif fld_char_type == "separate": + if len(complex_field_stack) == 0: + return _empty_result_with_message(results.warning( + "ignoring complex field separator character without corresponding start character", + )) + complex_field_separate = complex_field_stack.pop() complex_field = parse_current_instr_text(complex_field_separate) complex_field_stack.append(complex_field) |
