From fce76110e02409b67ad977ae0077adf55ca58065 Mon Sep 17 00:00:00 2001 From: Justin Luth Date: Tue, 13 Jul 2021 10:12:21 +0200 Subject: tdf#82111 rtf import: ensure CR before section break In other places, there were caveats for applying a CR when inserting instead of importing, or when in a header, but none of those seem to apply in this case. A section cannot occur in a table, and anytime a section occurs, it ought to finish off the paragraph. So a simple clause seems good enough here. There were basically two different existing unit tests that match this condition, and neither of them were currently mis-handled. I safely adapted one of them to imitate the error condition I was addressing. Change-Id: Ie8ccd3978276bf10321e0bf80141572f40102874 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/118819 Tested-by: Jenkins Reviewed-by: Justin Luth Reviewed-by: Miklos Vajna --- sw/qa/extras/rtfexport/data/pgndec.rtf | 1 + sw/qa/extras/rtfexport/rtfexport.cxx | 5 +++++ writerfilter/source/rtftok/rtfdispatchsymbol.cxx | 3 +++ 3 files changed, 9 insertions(+) diff --git a/sw/qa/extras/rtfexport/data/pgndec.rtf b/sw/qa/extras/rtfexport/data/pgndec.rtf index 7f38c69101b8..bc53633e7a66 100644 --- a/sw/qa/extras/rtfexport/data/pgndec.rtf +++ b/sw/qa/extras/rtfexport/data/pgndec.rtf @@ -1,5 +1,6 @@ {\rtf1 \pard\plain \ltrpar\ql \li0\ri0\sa200\sl276\slmult1\widctlpar\wrapdefault\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0 \rtlch\fcs1 \af31507\afs22\alang1025 \ltrch\fcs0 +\par {\field\fldedit {\*\fldinst { PAGE \\* MERGEFORMAT } diff --git a/sw/qa/extras/rtfexport/rtfexport.cxx b/sw/qa/extras/rtfexport/rtfexport.cxx index 714aa8f468b1..326c63a3cbae 100644 --- a/sw/qa/extras/rtfexport/rtfexport.cxx +++ b/sw/qa/extras/rtfexport/rtfexport.cxx @@ -1223,6 +1223,11 @@ DECLARE_RTFEXPORT_TEST(testPgndec, "pgndec.rtf") CPPUNIT_ASSERT_EQUAL( style::NumberingType::ARABIC, getProperty(xPageStyles->getByName(pageStyleName), "NumberingType")); + + // tdf#82111 ensure a pargraph exists before a section break. + // This was only two paragraphs, and both page number fields were in one para on page 2 ("11"). + getParagraph(2, "1"); + CPPUNIT_ASSERT_EQUAL(3, getParagraphs()); } DECLARE_RTFEXPORT_TEST(testTdf98806, "tdf98806.rtf") diff --git a/writerfilter/source/rtftok/rtfdispatchsymbol.cxx b/writerfilter/source/rtftok/rtfdispatchsymbol.cxx index 88d303c0b2c1..df02f36fc18a 100644 --- a/writerfilter/source/rtftok/rtfdispatchsymbol.cxx +++ b/writerfilter/source/rtftok/rtfdispatchsymbol.cxx @@ -133,6 +133,9 @@ RTFError RTFDocumentImpl::dispatchSymbol(RTFKeyword nKeyword) break; case RTFKeyword::SECT: { + if (m_bNeedCr) + dispatchSymbol(RTFKeyword::PAR); + m_bHadSect = true; if (m_bIgnoreNextContSectBreak) m_bIgnoreNextContSectBreak = false; -- cgit