diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/client/qwaylanddataoffer.cpp | 33 |
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; } } } |