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 cffa53b63b8186f2b5533d96899dbf17f61f1c69 Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Fri Apr 4 09:43:43 2025 +0200 Commit: Xisco Fauli <xiscofa...@libreoffice.org> CommitDate: Mon Apr 7 22:17:39 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/+/183710 Tested-by: Jenkins Reviewed-by: Miklos Vajna <vmik...@collabora.com> (cherry picked from commit e435dc6ca1a898f4e806127257c9acc627c080cc) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/183771 Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org> (cherry picked from commit 452fb8e9373c3add5937d4751fe6901d07c46d55) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/183800 diff --git a/sw/qa/writerfilter/dmapper/DomainMapper_Impl.cxx b/sw/qa/writerfilter/dmapper/DomainMapper_Impl.cxx index 05d49624171b..742ee3940277 100644 --- a/sw/qa/writerfilter/dmapper/DomainMapper_Impl.cxx +++ b/sw/qa/writerfilter/dmapper/DomainMapper_Impl.cxx @@ -469,6 +469,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 2e225a1c86e0..18a5dbe72dab 100644 --- a/sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx +++ b/sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx @@ -650,7 +650,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