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:
parent
07d78b38fb
commit
97f9af714e
BIN
sw/qa/extras/ooxmlexport/data/tdf125038b.docx
Normal file
BIN
sw/qa/extras/ooxmlexport/data/tdf125038b.docx
Normal file
Binary file not shown.
@ -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: */
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user