sw/qa/writerfilter/dmapper/DomainMapper_Impl.cxx | 7 +++++++ sw/qa/writerfilter/dmapper/data/if-field.docx |binary sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx | 10 +++++++++- 3 files changed, 16 insertions(+), 1 deletion(-)
New commits: commit 731bc2da906ebc9d8f657909f569bc4dc0beda7e Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Fri Apr 4 09:43:43 2025 +0200 Commit: Caolán McNamara <caolan.mcnam...@collabora.com> CommitDate: Fri Apr 4 12:15:17 2025 +0200 tdf#165941 DOCX import: fix unhandled exc while removing dummy para in table The bugdoc can't be opened in Writer but Word considers it valid. This went wrong in commit 97f9af714ea1c46e498fa99f7ca34fc1708d38a6 (Related: tdf#125038 DOCX import: fix unexpected linebreak inside IF condition, 2019-10-30), because now we may have a range that is crossing a table of section boundary: this is a valid range for a field start/end in Word, but not in Writer. Fix the problem by handling exceptions from createTextCursorByRange() in DomainMapper_Impl::RemoveDummyParaForTableInSection(): we already assumed previously that the created cursor may be an empty reference, just the exception case was unexpected. The bigger problem is that Writer fields can't expand to multi-paragraph content while Word can do that, but that was a problem before the above commit, so is not addressed here. Change-Id: I718b702e68da5bf90eb4af95bb179d2e33abadc3 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/183695 Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com> Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Tested-by: Caolán McNamara <caolan.mcnam...@collabora.com> diff --git a/sw/qa/writerfilter/dmapper/DomainMapper_Impl.cxx b/sw/qa/writerfilter/dmapper/DomainMapper_Impl.cxx index 8bbf6035a40b..040282e79d62 100644 --- a/sw/qa/writerfilter/dmapper/DomainMapper_Impl.cxx +++ b/sw/qa/writerfilter/dmapper/DomainMapper_Impl.cxx @@ -471,6 +471,13 @@ CPPUNIT_TEST_FIXTURE(Test, testParaStyleLostNumbering) xStyle->getPropertyValue("NumberingStyleName") >>= aNumberingStyleName; CPPUNIT_ASSERT(!aNumberingStyleName.isEmpty()); } + +CPPUNIT_TEST_FIXTURE(Test, testIfField) +{ + // Without the accompanying fix in place, this test would have failed, the document failed to + // load. + loadFromFile(u"if-field.docx"); +} } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/qa/writerfilter/dmapper/data/if-field.docx b/sw/qa/writerfilter/dmapper/data/if-field.docx new file mode 100644 index 000000000000..9f26ab6b84a5 Binary files /dev/null and b/sw/qa/writerfilter/dmapper/data/if-field.docx differ diff --git a/sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx b/sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx index b8294b27c829..0c905ea6e42e 100644 --- a/sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx +++ b/sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx @@ -669,7 +669,15 @@ void DomainMapper_Impl::RemoveDummyParaForTableInSection() if (!xTextAppend.is()) return; - uno::Reference< text::XTextCursor > xCursor = xTextAppend->createTextCursorByRange(pSectionContext->GetStartingRange()); + uno::Reference< text::XTextCursor > xCursor; + try + { + xCursor = xTextAppend->createTextCursorByRange(pSectionContext->GetStartingRange()); + } + catch (const uno::Exception&) + { + TOOLS_WARN_EXCEPTION("writerfilter.dmapper", "failed to create text cursor by range"); + } // Remove the extra NumPicBullets from the document, // which get attached to the first paragraph in the