diff --git a/sw/qa/extras/ooxmlexport/data/tdf125038b.docx b/sw/qa/extras/ooxmlexport/data/tdf125038b.docx new file mode 100644 index 000000000000..3aa189daded8 Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/tdf125038b.docx differ diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx index 6dd91d44960a..82237bffa368 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx @@ -49,6 +49,23 @@ DECLARE_OOXMLIMPORT_TEST(testTdf125038, "tdf125038.docx") CPPUNIT_ASSERT_EQUAL(OUString("phone: \t1234567890"), aActual); } +DECLARE_OOXMLIMPORT_TEST(testTdf125038b, "tdf125038b.docx") +{ + // Load a document with an IF field, where the IF field command contains a paragraph break. + uno::Reference xTextDocument(mxComponent, uno::UNO_QUERY); + uno::Reference xParagraphAccess(xTextDocument->getText(), uno::UNO_QUERY); + uno::Reference xParagraphs = xParagraphAccess->createEnumeration(); + CPPUNIT_ASSERT(xParagraphs->hasMoreElements()); + xParagraphs->nextElement(); + CPPUNIT_ASSERT(xParagraphs->hasMoreElements()); + xParagraphs->nextElement(); + + // Without the accompanying fix in place, this test would have failed with: + // - Expression: !xParagraphs->hasMoreElements() + // i.e. the document had 3 paragraphs, while only 2 was expected. + CPPUNIT_ASSERT(!xParagraphs->hasMoreElements()); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx index 276f408451f3..c0492804e119 100644 --- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx +++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx @@ -1250,6 +1250,21 @@ void DomainMapper_Impl::finishParagraph( const PropertyMapPtr& pPropertyMap, con { if (m_bDiscardHeaderFooter) return; + + if (!m_aFieldStack.empty()) + { + FieldContextPtr pFieldContext = m_aFieldStack.back(); + if (pFieldContext && !pFieldContext->IsCommandCompleted()) + { + std::vector aCommandParts = pFieldContext->GetCommandParts(); + if (!aCommandParts.empty() && aCommandParts[0] == "IF") + { + // Conditional text field conditions don't support linebreaks in Writer. + return; + } + } + } + #ifdef DBG_UTIL TagLogger::getInstance().startElement("finishParagraph"); #endif