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 564ec69c3d2cf591c80dbb561bf04fe3c6180f31
Author:     Vasily Melenchuk <vasily.melenc...@cib.de>
AuthorDate: Thu Oct 6 12:37:31 2022 +0300
Commit:     Thorsten Behrens <thorsten.behr...@allotropia.de>
CommitDate: Mon Oct 10 10:39:02 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>
    (cherry picked from commit fb7da82cac17f05fce13cdd0094bbd5159f5404d)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141058
    Reviewed-by: Thorsten Behrens <thorsten.behr...@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 f4844765fc68..4011a17d5ecb 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
@@ -1502,7 +1502,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 3e1caf7d0322..e859c01c9992 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 = ""; }

Reply via email to