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 <vmiklos@collabora.com>
Tested-by: Jenkins
This commit is contained in:
Miklos Vajna 2019-10-30 16:02:35 +01:00
parent 07d78b38fb
commit 97f9af714e
3 changed files with 32 additions and 0 deletions

Binary file not shown.

View File

@ -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: */

View File

@ -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