sw/qa/extras/ooxmlexport/data/line-break-in-ref.docx |binary sw/qa/extras/ooxmlexport/ooxmlexport22.cxx | 12 ++++++++++++ sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx | 2 +- 3 files changed, 13 insertions(+), 1 deletion(-)
New commits: commit aa689d596c44c1c51ab9345df5d063768936fe74 Author: Jaume Pujantell <[email protected]> AuthorDate: Thu May 29 14:32:18 2025 +0200 Commit: Jaume Pujantell <[email protected]> CommitDate: Fri Jun 13 12:05:20 2025 +0200 tdf#166940 sw: defer line break in ref field In Writer ref fields contain only text strings and it does not support line breaks. So, to avoid misplacement of the content on load, we defer the breaks until after the field is finished. Change-Id: I3d9a78743deb0d4f7f187a5c59b58e74ae3b20d8 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/186008 Reviewed-by: Miklos Vajna <[email protected]> Tested-by: Jenkins CollaboraOffice <[email protected]> (cherry picked from commit e0119fbf861af288e3efe55efcd9aa88adaff80f) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/186450 Tested-by: Jenkins Reviewed-by: Jaume Pujantell <[email protected]> diff --git a/sw/qa/extras/ooxmlexport/data/line-break-in-ref.docx b/sw/qa/extras/ooxmlexport/data/line-break-in-ref.docx new file mode 100644 index 000000000000..a2332eac79ba Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/line-break-in-ref.docx differ diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport22.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport22.cxx index 3f944c8d0f8e..f94fc0ad1f91 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport22.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport22.cxx @@ -369,6 +369,18 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf166511) CPPUNIT_ASSERT_EQUAL(aDiffIds.size(), nIds); } +CPPUNIT_TEST_FIXTURE(Test, testLineBreakInRef) +{ + loadAndSave("line-break-in-ref.docx"); + xmlDocUniquePtr pXmlDoc = parseExport(u"word/document.xml"_ustr); + + // Without the fix if fails with + // assertion failed + // - Expression: xmlXPathNodeSetGetLength(pXmlNodes) > 0 + // - In <>, XPath '/w:document/w:body/w:p[1]/w:r[4]/w:t' not found + assertXPathContent(pXmlDoc, "/w:document/w:body/w:p[1]/w:r[4]/w:t", u"Text1"); +} + } // end of anonymous namespace CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx b/sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx index 6b2476e666e7..c81255112abe 100644 --- a/sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx +++ b/sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx @@ -2211,7 +2211,7 @@ void DomainMapper_Impl::finishParagraph( const PropertyMapPtr& pPropertyMap, con if (pFieldContext && pFieldContext->IsCommandCompleted()) { - if (pFieldContext->GetFieldId() == FIELD_IF) + if (pFieldContext->GetFieldId() == FIELD_IF || pFieldContext->GetFieldId() == FIELD_REF) { // Conditional text fields can't contain newlines, finish the paragraph later. FieldParagraph aFinish{pPropertyMap, bRemove};
