Skip to content

Commit

Permalink
QMimeData: fix setData on URI list without ending CRLF
Browse files Browse the repository at this point in the history
Commit 8d127c5 refactored this code
from QByteArray::split to manually iterate over the list (and
QStringTokenizer doesn't work for QByteArray), so we missed the last
element in the iteration.

Pick-to: 6.7
Fixes: QTBUG-124580
Change-Id: I455fe22ef4ad4b2f9b01fffd17c867f6ed350af7
Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
Reviewed-by: David Faure <david.faure@kdab.com>
  • Loading branch information
thiagomacieira committed Apr 22, 2024
1 parent f5fa811 commit 038c199
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/corelib/kernel/qmimedata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ static QList<QVariant> dataToUrls(QByteArrayView text)
if (from >= text.size())
break;
}
if (from != text.size()) {
const auto bav = QByteArrayView(begin + from, text.end()).trimmed();
if (!bav.isEmpty())
list.push_back(QUrl::fromEncoded(bav));
}
return list;
}

Expand Down
8 changes: 8 additions & 0 deletions tests/auto/corelib/kernel/qmimedata/tst_qmimedata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ void tst_QMimeData::data() const
QCOMPARE(mimeData.data("text/markdown"), QByteArray("vikings"));
QCOMPARE(mimeData.data("text/html"), QByteArray("ninjas"));
QCOMPARE(mimeData.data("text/plain"), QByteArray("pirates"));

// URI list
QByteArray list = "https://example.com/\r\nhttps://example.net/\r\nhttps://example.org/\r\n";
mimeData.setData("text/uri-list", list);
QCOMPARE(mimeData.data("text/uri-list"), list);

mimeData.setData("text/uri-list", list.chopped(2)); // without the ending CRLF
QCOMPARE(mimeData.data("text/uri-list"), list);
}

void tst_QMimeData::formats() const
Expand Down

0 comments on commit 038c199

Please sign in to comment.