From dcc605beb6d82ef89d1088eb8b1bd25f2f1f3bd6 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Sun, 17 Dec 2017 17:10:23 +0100 Subject: Chop a possible trailing \0 from retrieved text Some apps (e.g. Chromium) explicitly append a \0 to the text they transmit through the clipboard. Remove that one, when we retrieve the text, so it doesn't become part of the text we're pasting. This was e.g. visible when pasting from chromium to the textedit example. Change-Id: I9445319e6e5ef304a364e14f794b16557a3cc919 Reviewed-by: Eskil Abrahamsen Blomfeldt Reviewed-by: Gatis Paeglis --- src/plugins/platforms/xcb/qxcbmime.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src/plugins/platforms/xcb/qxcbmime.cpp') diff --git a/src/plugins/platforms/xcb/qxcbmime.cpp b/src/plugins/platforms/xcb/qxcbmime.cpp index 2848446098..58e2e8c0e6 100644 --- a/src/plugins/platforms/xcb/qxcbmime.cpp +++ b/src/plugins/platforms/xcb/qxcbmime.cpp @@ -160,9 +160,10 @@ QVector QXcbMime::mimeAtomsForFormat(QXcbConnection *connection, con return atoms; } -QVariant QXcbMime::mimeConvertToFormat(QXcbConnection *connection, xcb_atom_t a, const QByteArray &data, const QString &format, +QVariant QXcbMime::mimeConvertToFormat(QXcbConnection *connection, xcb_atom_t a, const QByteArray &d, const QString &format, QVariant::Type requestedType, const QByteArray &encoding) { + QByteArray data = d; QString atomName = mimeAtomToString(connection, a); // qDebug() << "mimeConvertDataToFormat" << format << atomName << data; @@ -182,8 +183,11 @@ QVariant QXcbMime::mimeConvertToFormat(QXcbConnection *connection, xcb_atom_t a, // special cases for string types if (format == QLatin1String("text/plain")) { - if (a == connection->atom(QXcbAtom::UTF8_STRING)) + if (data.endsWith('\0')) + data.chop(1); + if (a == connection->atom(QXcbAtom::UTF8_STRING)) { return QString::fromUtf8(data); + } if (a == XCB_ATOM_STRING || a == connection->atom(QXcbAtom::TEXT)) return QString::fromLatin1(data); @@ -221,6 +225,9 @@ QVariant QXcbMime::mimeConvertToFormat(QXcbConnection *connection, xcb_atom_t a, } } } + // 8 byte encoding, remove a possible 0 at the end + if (data.endsWith('\0')) + data.chop(1); } if (atomName == format) -- cgit v1.2.3