diff options
author | Lars Knoll <lars.knoll@qt.io> | 2017-12-17 17:10:23 +0100 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2017-12-29 08:14:55 +0000 |
commit | dcc605beb6d82ef89d1088eb8b1bd25f2f1f3bd6 (patch) | |
tree | baffa960cf544f7dfc77c9e99014882f8c0dea38 /src/plugins/platforms/xcb/qxcbmime.cpp | |
parent | a779d68256ba2568f47aab9c5efbcef0cf8c277e (diff) |
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 <eskil.abrahamsen-blomfeldt@qt.io>
Reviewed-by: Gatis Paeglis <gatis.paeglis@qt.io>
Diffstat (limited to 'src/plugins/platforms/xcb/qxcbmime.cpp')
-rw-r--r-- | src/plugins/platforms/xcb/qxcbmime.cpp | 11 |
1 files changed, 9 insertions, 2 deletions
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<xcb_atom_t> 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) |