sw/qa/extras/rtfimport/data/tdf169298.rtf | 7 ++++++ sw/qa/extras/rtfimport/rtfimport2.cxx | 25 ++++++++++++++++++++++ sw/source/writerfilter/rtftok/rtfdocumentimpl.cxx | 1 3 files changed, 33 insertions(+)
New commits: commit eb49b1a6cef98bef595cc7386657d886c2bb8cb7 Author: Mike Kaganski <[email protected]> AuthorDate: Fri Feb 13 16:32:15 2026 +0500 Commit: Mike Kaganski <[email protected]> CommitDate: Fri Feb 13 16:23:55 2026 +0100 Related: tdf#169298 Destination::DOCVAR handles CR/LF itself, too Otherwise, these codes coming from variable values, get dispatched to the documet body. Change-Id: I35eff5d87f9d8acedb1749644900116bd8524797 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/199335 Reviewed-by: Mike Kaganski <[email protected]> Tested-by: Jenkins diff --git a/sw/qa/extras/rtfimport/data/tdf169298.rtf b/sw/qa/extras/rtfimport/data/tdf169298.rtf new file mode 100644 index 000000000000..98808820f5c5 --- /dev/null +++ b/sw/qa/extras/rtfimport/data/tdf169298.rtf @@ -0,0 +1,7 @@ +{ tf1 +{\*\docvar {foobar}{foo\'0d\'0abar}} +This document contains some document variables: +\par {ield{\*ldinst { DOCVARIABLE foobar \* MERGEFORMAT }}{ldrslt foo +\par bar}} +\par +} \ No newline at end of file diff --git a/sw/qa/extras/rtfimport/rtfimport2.cxx b/sw/qa/extras/rtfimport/rtfimport2.cxx index 98d67054346d..32200661f799 100644 --- a/sw/qa/extras/rtfimport/rtfimport2.cxx +++ b/sw/qa/extras/rtfimport/rtfimport2.cxx @@ -1100,6 +1100,31 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf167254) // It must not crash on import } +CPPUNIT_TEST_FIXTURE(Test, testTdf169298_CrLfDontSpillToDocumentBody) +{ + // Given a document with a document variable value contailing foo\'0d\'0abar + createSwDoc("tdf169298.rtf"); + + // The sequence must not cause newlines to appear in the beginning of the document text. + + // Before fix, this was 5: + CPPUNIT_ASSERT_EQUAL(3, getParagraphs()); + + // Before this paragraph, there were two empty paragraphs: + CPPUNIT_ASSERT_EQUAL(u"This document contains some document variables:"_ustr, + getParagraph(1)->getString()); + + CPPUNIT_ASSERT_EQUAL(u""_ustr, getParagraph(2)->getString()); + + // It is questionable what *this* paragraph should display. Currently we strip all the codes + // below 0x20, and refresh the variable on document load. Word replaces almost all such codes + // with '_', except \'0a and \'0d, which it replaces with characters 'a' and 'd'; the variable + // value would become "boodabar". But Word also uses cached field expansion; so it will show + // the previous "foo{newline}bar", until refreshed. + // I comment out the last line test because of that. + // CPPUNIT_ASSERT_EQUAL(u"foobar"_ustr, getParagraph(3)->getString()); +} + // tests should only be added to rtfIMPORT *if* they fail round-tripping in rtfEXPORT } // end of anonymous namespace CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sw/source/writerfilter/rtftok/rtfdocumentimpl.cxx b/sw/source/writerfilter/rtftok/rtfdocumentimpl.cxx index 7cd8d0ce6629..9f0b4b920070 100644 --- a/sw/source/writerfilter/rtftok/rtfdocumentimpl.cxx +++ b/sw/source/writerfilter/rtftok/rtfdocumentimpl.cxx @@ -1381,6 +1381,7 @@ RTFError RTFDocumentImpl::resolveChars(char ch) // note: apparently \'0d\'0a is interpreted as 2 breaks, not 1 if ((ch == ' ' || ch == ' ') && m_aStates.top().getDestination() != Destination::DOCCOMM + && m_aStates.top().getDestination() != Destination::DOCVAR && m_aStates.top().getDestination() != Destination::LEVELNUMBERS && m_aStates.top().getDestination() != Destination::LEVELTEXT) {
