From a32742936d6da1167c5b8200ef8b2827daf4c13f Mon Sep 17 00:00:00 2001 From: Michael Weghorn Date: Mon, 16 May 2022 17:24:28 +0200 Subject: 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 (cherry picked from commit 6fc3ec85a32cd70216b4bbf21e479b4fc32a38dc) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134451 Tested-by: Ilmari Lauhakangas Reviewed-by: Ilmari Lauhakangas --- vcl/qt5/QtTransferable.cxx | 5 +++++ 1 file changed, 5 insertions(+) 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(aLocaleString.getStr()), aLocaleString.getLength()); } + else if (bWantUTF16) + { + aByteArray = QByteArray(reinterpret_cast(aString.getStr()), + aString.getLength() * 2); + } else return QVariant(toQString(aString)); } -- cgit