sw/qa/extras/ooxmlexport/data/tdf125038b.docx |binary sw/qa/extras/ooxmlexport/ooxmlexport14.cxx | 17 +++++++++++++++++ writerfilter/source/dmapper/DomainMapper_Impl.cxx | 15 +++++++++++++++ 3 files changed, 32 insertions(+)
New commits: commit 97f9af714ea1c46e498fa99f7ca34fc1708d38a6 Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Wed Oct 30 16:02:35 2019 +0100 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Wed Oct 30 22:02:15 2019 +0100 Related: tdf#125038 DOCX import: fix unexpected linebreak inside IF condition Writer body text is expected to only contain the result of the field. So in case both the field command and the field result contains a linebreak, we need to make sure that linebreaks are ignored in the field command for field types where the Writer field implementation expects a single string. With this, the number of paragraphs in the bugdoc is now correct. Change-Id: I42f208d6943750ba2e8f88b52c373f6ca9cb2b71 Reviewed-on: https://gerrit.libreoffice.org/81786 Reviewed-by: Miklos Vajna <vmik...@collabora.com> Tested-by: Jenkins 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<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY); + uno::Reference<container::XEnumerationAccess> xParagraphAccess(xTextDocument->getText(), uno::UNO_QUERY); + uno::Reference<container::XEnumeration> 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<OUString> 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 _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits