vcl/qt5/QtTransferable.cxx |    5 +++++
 1 file changed, 5 insertions(+)

New commits:
commit a32742936d6da1167c5b8200ef8b2827daf4c13f
Author:     Michael Weghorn <[email protected]>
AuthorDate: Mon May 16 17:24:28 2022 +0200
Commit:     Michael Weghorn <[email protected]>
CommitDate: Wed May 18 09:33:41 2022 +0200

    tdf#137639 qt: UTF-16-encode mime data for "text/plain;charset=utf-16"
    
    Return a `QVariant` from a `QByteArray` containing the UTF-16-encoded
    characters when mime data for mime type "text/plain;charset=utf-16"
    is requested in `QtMimeData::retrieveData`, rather than
    a `QVariant` created from a a `QString`, to ensure that UTF-16
    encoded data is actually used in the end.
    
    While `QString` uses UTF-16 encoding itself,
    `QMimeDataPrivate::retrieveTypedData` from the Qt library
    would convert the retrieved `QString` data to UTF-8 [1],
    resulting in a mismatch because UTF-8 encoded data would
    actually be returned when UTF-16-encoded one has
    been requested.
    
    This gets called as follows:
    
        0 QtMimeData::retrieveData
        1 QMimeDataPrivate::retrieveTypedData
        2 QMimeData::data
        3 QtMimeData::deepCopy
    
    [1] 
https://code.qt.io/cgit/qt/qtbase.git/tree/src/corelib/kernel/qmimedata.cpp?h=6.3.0#n212
    
    Change-Id: I3db1476838336682584145fb43d397c8eed29ce2
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134456
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <[email protected]>
    (cherry picked from commit 6fc3ec85a32cd70216b4bbf21e479b4fc32a38dc)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134451
    Tested-by: Ilmari Lauhakangas <[email protected]>
    Reviewed-by: Ilmari Lauhakangas <[email protected]>

diff --git a/vcl/qt5/QtTransferable.cxx b/vcl/qt5/QtTransferable.cxx
index 1ab07dbb6224..24073c9fd792 100644
--- a/vcl/qt5/QtTransferable.cxx
+++ b/vcl/qt5/QtTransferable.cxx
@@ -339,6 +339,11 @@ QVariant QtMimeData::retrieveData(const QString& mimeType, 
QMetaType) const
             aByteArray = QByteArray(reinterpret_cast<const 
char*>(aLocaleString.getStr()),
                                     aLocaleString.getLength());
         }
+        else if (bWantUTF16)
+        {
+            aByteArray = QByteArray(reinterpret_cast<const 
char*>(aString.getStr()),
+                                    aString.getLength() * 2);
+        }
         else
             return QVariant(toQString(aString));
     }

Reply via email to