diff options
author | Michael Weghorn <m.weghorn@posteo.de> | 2022-05-16 17:24:28 +0200 |
---|---|---|
committer | Michael Weghorn <m.weghorn@posteo.de> | 2022-05-18 06:48:01 +0200 |
commit | 6fc3ec85a32cd70216b4bbf21e479b4fc32a38dc (patch) | |
tree | f544c575e4cad25c11fb6443f966f2ce16aaff13 /vcl/qt5 | |
parent | 9b06af2adddc49414adc135f3d08dcc88c896058 (diff) |
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 <m.weghorn@posteo.de>
Diffstat (limited to 'vcl/qt5')
-rw-r--r-- | vcl/qt5/QtTransferable.cxx | 5 |
1 files changed, 5 insertions, 0 deletions
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)); } |