sw/qa/extras/rtfexport/data/tdf151370.rtf | 3 +++ sw/qa/extras/rtfexport/rtfexport5.cxx | 18 ++++++++++++++++++ writerfilter/source/rtftok/rtfdocumentimpl.cxx | 2 +- writerfilter/source/rtftok/rtfdocumentimpl.hxx | 2 +- 4 files changed, 23 insertions(+), 2 deletions(-)
New commits: commit 0d545f1f0afc93bd568f8172a134ab9196529809 Author: Vasily Melenchuk <vasily.melenc...@cib.de> AuthorDate: Thu Oct 6 12:37:31 2022 +0300 Commit: Vasily Melenchuk <vasily.melenc...@cib.de> CommitDate: Fri Oct 7 11:06:48 2022 +0200 tdf#151370: RTF import: docvar name/value can have several sequences In case of unicode used there can be tokens, replacements, etc. So it is better to collect and join all received strings, not overwrite with just last received. Change-Id: I2b6ce465d87db4ee30987cbe0ecce1470386242f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141007 Tested-by: Jenkins Reviewed-by: Michael Stahl <michael.st...@allotropia.de> diff --git a/sw/qa/extras/rtfexport/data/tdf151370.rtf b/sw/qa/extras/rtfexport/data/tdf151370.rtf new file mode 100644 index 000000000000..e555d5c58cd2 --- /dev/null +++ b/sw/qa/extras/rtfexport/data/tdf151370.rtf @@ -0,0 +1,3 @@ +{\rtf1\adeflang1025\ansi\ansicpg1250 +{\*\docvar {LocalChars\'c1rv\'edzturoT\'fck\'f6rf\'far\'f3g\'e9p}{\'e1rv\'edzturot\'fck\'f6rf\'far\'f3g\'e9p}} +} \ No newline at end of file diff --git a/sw/qa/extras/rtfexport/rtfexport5.cxx b/sw/qa/extras/rtfexport/rtfexport5.cxx index 1dbacde70bea..6c3d6c6c8471 100644 --- a/sw/qa/extras/rtfexport/rtfexport5.cxx +++ b/sw/qa/extras/rtfexport/rtfexport5.cxx @@ -848,6 +848,24 @@ DECLARE_RTFEXPORT_TEST(testTdf150267, "tdf150267.rtf") CPPUNIT_ASSERT_EQUAL(OUString("Hello World"), getProperty<OUString>(xFieldMaster, "Content")); } +DECLARE_RTFEXPORT_TEST(testTdf151370, "tdf151370.rtf") +{ + uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY); + uno::Reference<text::XTextFieldsSupplier> xSupplier(xModel, uno::UNO_QUERY); + uno::Reference<container::XNameAccess> xTextFieldMasters = xSupplier->getTextFieldMasters(); + // Here we try to read/write docvar having non-ascii name and value. So it is encoded in Unicode + OUString sFieldName(u"com.sun.star.text.fieldmaster.User." + "LocalChars\u00c1\u0072\u0076\u00ed\u007a\u0074\u0075\u0072\u006f\u0054" + "\u00fc\u006b\u00f6\u0072\u0066\u00fa\u0072\u00f3\u0067\u00e9\u0070"); + CPPUNIT_ASSERT_EQUAL(sal_True, xTextFieldMasters->hasByName(sFieldName)); + + auto xFieldMaster = xTextFieldMasters->getByName(sFieldName); + CPPUNIT_ASSERT_EQUAL( + OUString(u"\u00e1\u0072\u0076\u00ed\u007a\u0074\u0075\u0072\u006f\u0074\u00fc" + "\u006b\u00f6\u0072\u0066\u00fa\u0072\u00f3\u0067\u00e9\u0070"), + getProperty<OUString>(xFieldMaster, "Content")); +} + DECLARE_RTFEXPORT_TEST(testTdf108416, "tdf108416.rtf") { uno::Reference<container::XNameAccess> xCharacterStyles(getStyles("CharacterStyles")); diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx index 7fa664ea26b1..8a888d8348f6 100644 --- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx +++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx @@ -1503,7 +1503,7 @@ void RTFDocumentImpl::text(OUString& rString) break; case Destination::DOCVAR: { - m_aStates.top().setDocVar(rString); + m_aStates.top().appendDocVar(rString); } break; case Destination::FONTTABLE: diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.hxx b/writerfilter/source/rtftok/rtfdocumentimpl.hxx index 208812fd4237..ac1263a41531 100644 --- a/writerfilter/source/rtftok/rtfdocumentimpl.hxx +++ b/writerfilter/source/rtftok/rtfdocumentimpl.hxx @@ -524,7 +524,7 @@ public: RTFInternalState getInternalState() const { return m_nInternalState; } RTFDocumentImpl* getDocumentImpl() { return m_pDocumentImpl; } OUString getDocVar() { return m_aDocVar; } - void setDocVar(OUString& aDocVar) { m_aDocVar = aDocVar; }; + void appendDocVar(OUString& aDocVar) { m_aDocVar += aDocVar; }; OUString getDocVarName() { return m_aDocVarName; } void setDocVarName(OUString& aDocVarName) { m_aDocVarName = aDocVarName; } void clearDocVarName() { m_aDocVarName = ""; }