tdf#106492 DOCX export: fix duplicated section break at doc end
There is always a section break at the end of a DOCX document, so in the
rare case when there is no text node between the end of a Writer section
and the end of the document make sure no duplicated section break is
written.
Change-Id: I3fcd852c1a63e2d707822ad08603e2d37386e439
Reviewed-on: https://gerrit.libreoffice.org/35499
Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
Tested-by: Jenkins <ci@libreoffice.org>
diff --git a/sw/qa/extras/ooxmlexport/data/tdf106492.docx b/sw/qa/extras/ooxmlexport/data/tdf106492.docx
new file mode 100644
index 0000000..72ff4be
--- /dev/null
+++ b/sw/qa/extras/ooxmlexport/data/tdf106492.docx
Binary files differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx
index 678e092..e7bc9cb 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx
@@ -420,6 +420,13 @@ DECLARE_OOXMLEXPORT_TEST(testUnbalancedColumns, "unbalanced-columns.docx")
CPPUNIT_ASSERT_EQUAL(true, getProperty<bool>(xTextSections->getByIndex(2), "DontBalanceTextColumns"));
}
DECLARE_OOXMLEXPORT_TEST(testTdf106492, "tdf106492.docx")
{
if (xmlDocPtr pXmlDoc = parseExport())
// This was 4: an additional sectPr was added to the document.
assertXPath(pXmlDoc, "//w:sectPr", 3);
}
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx
index c4057cd..88acbf8 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -5449,9 +5449,15 @@ void DocxAttributeOutput::SectionBreak( sal_uInt8 nC, const WW8_SepInfo* pSectio
case msword::PageBreak:
if ( pSectionInfo )
{
// Detect when the current node is the last node in the
// document: the last section is written explicitly in
// DocxExport::WriteMainText(), don't duplicate that here.
SwNodeIndex aCurrentNode(m_rExport.m_pCurPam->GetNode());
SwNodeIndex aLastNode(m_rExport.m_pDoc->GetNodes().GetEndOfContent(), -1);
// don't add section properties if this will be the first
// paragraph in the document
if ( !m_bParagraphOpened && !m_bIsFirstParagraph)
if ( !m_bParagraphOpened && !m_bIsFirstParagraph && aCurrentNode != aLastNode)
{
// Create a dummy paragraph if needed
m_pSerializer->startElementNS( XML_w, XML_p, FSEND );