vcl/qt5/QtTransferable.cxx | 5 +++++
1 file changed, 5 insertions(+)
New commits:
commit 6fc3ec85a32cd70216b4bbf21e479b4fc32a38dc
Author: Michael Weghorn <[email protected]>
AuthorDate: Mon May 16 17:24:28 2022 +0200
Commit: Michael Weghorn <[email protected]>
CommitDate: Wed May 18 06:48:01 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]>
diff --git a/vcl/qt5/QtTransferable.cxx b/vcl/qt5/QtTransferable.cxx
index db52eed66d0b..d9e0beaa71d3 100644
--- a/vcl/qt5/QtTransferable.cxx
+++ b/vcl/qt5/QtTransferable.cxx
@@ -338,6 +338,11 @@ QVariant QtMimeData::retrieveData(const QString& mimeType,
QMetaType) const
OString aLocaleString(OUStringToOString(aString,
osl_getThreadTextEncoding()));
aByteArray = QByteArray(aLocaleString.getStr(),
aLocaleString.getLength());
}
+ else if (bWantUTF16)
+ {
+ aByteArray = QByteArray(reinterpret_cast<const
char*>(aString.getStr()),
+ aString.getLength() * 2);
+ }
else
return QVariant(toQString(aString));
}