summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKai Uwe Broulik <kde@privat.broulik.de>2023-11-13 17:33:12 +0100
committerKai Uwe Broulik <kde@privat.broulik.de>2023-12-04 21:30:21 +0100
commit7de5d7c05276c179c9951c718c6fc5ccd18982aa (patch)
tree4e9ed6d335117d94482de5696b4f200f53a51c89 /src
parent8e57e8b51b2b701c5520f37b7d78de5b3c488500 (diff)
QWaylandMimeData: Check text/x-moz-urls for UTF-16
And fall back to UTF-8 if it's not. When dragging a picture out of Chrome, it sends a simple URL as UTF-8 under text/x-moz-urls. QXcbMime has this fall-back, too but I originally didn't consider it necessary. Pick-to: 6.6 6.5 Change-Id: I52378cfc354de342623e5dd3f7e1d028951e8dab Reviewed-by: David Edmundson <davidedmundson@kde.org>
Diffstat (limited to 'src')
-rw-r--r--src/client/qwaylanddataoffer.cpp33
1 files changed, 23 insertions, 10 deletions
diff --git a/src/client/qwaylanddataoffer.cpp b/src/client/qwaylanddataoffer.cpp
index c21113a80..c2fc9f095 100644
--- a/src/client/qwaylanddataoffer.cpp
+++ b/src/client/qwaylanddataoffer.cpp
@@ -42,20 +42,33 @@ static QByteArray convertData(const QString &originalMime, const QString &newMim
// see also qtbase/src/plugins/platforms/xcb/qxcbmime.cpp
if (originalMime == uriList() && newMime == mozUrl()) {
if (data.size() > 1) {
- const QString str = QString::fromUtf16(
- reinterpret_cast<const char16_t *>(data.constData()), data.size() / 2);
- if (!str.isNull()) {
+ const quint8 byte0 = data.at(0);
+ const quint8 byte1 = data.at(1);
+
+ if ((byte0 == 0xff && byte1 == 0xfe) || (byte0 == 0xfe && byte1 == 0xff)
+ || (byte0 != 0 && byte1 == 0) || (byte0 == 0 && byte1 != 0)) {
QByteArray converted;
- const auto urls = QStringView{str}.split(u'\n');
- // Only the URL is interesting, skip the page title.
- for (int i = 0; i < urls.size(); i += 2) {
- const QUrl url(urls.at(i).trimmed().toString());
- if (url.isValid()) {
- converted += url.toEncoded();
- converted += "\r\n";
+ const QString str = QString::fromUtf16(
+ reinterpret_cast<const char16_t *>(data.constData()), data.size() / 2);
+ if (!str.isNull()) {
+ const auto urls = QStringView{str}.split(u'\n');
+ // Only the URL is interesting, skip the page title.
+ for (int i = 0; i < urls.size(); i += 2) {
+ const QUrl url(urls.at(i).trimmed().toString());
+ if (url.isValid()) {
+ converted += url.toEncoded();
+ converted += "\r\n";
+ }
}
}
return converted;
+ // 8 byte encoding, remove a possible 0 at the end.
+ } else {
+ QByteArray converted = data;
+ if (converted.endsWith('\0'))
+ converted.chop(1);
+ converted += "\r\n";
+ return converted;
}
}
}