Skip to content

Commit

Permalink
test: migrate QNetworkReply test to QRegularExpression
Browse files Browse the repository at this point in the history
This is part of the migration of qtbase from QRexExp to
QRegularExpression.

Task-number: QTBUG-72587
Change-Id: Ibdd3f63d9069c3f01dfe8431bcc64bde4f2aa569
Reviewed-by: Timur Pocheptsov <[email protected]>
Reviewed-by: Edward Welbourne <[email protected]>
  • Loading branch information
sgaist committed Jun 10, 2019
1 parent 605dc42 commit 16cc3ea
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
4 changes: 2 additions & 2 deletions tests/auto/network-settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ class QtNetworkSettings
static bool compareReplyFtp(QByteArray const& actual)
{
// output would be e.g. "220 (vsFTPd 2.3.5)\r\n221 Goodbye.\r\n"
QRegExp ftpVersion(QStringLiteral("220 \\(vsFTPd \\d+\\.\\d+.\\d+\\)\\r\\n221 Goodbye.\\r\\n"));
return ftpVersion.exactMatch(actual);
QRegularExpression ftpVersion(QRegularExpression::anchoredPattern(QStringLiteral("220 \\(vsFTPd \\d+\\.\\d+.\\d+\\)\\r\\n221 Goodbye.\\r\\n")));
return ftpVersion.match(actual).hasMatch();
}

static bool hasIPv6()
Expand Down
9 changes: 6 additions & 3 deletions tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
#include <QtCore/QEventLoop>
#include <QtCore/QFile>
#include <QtCore/QRandomGenerator>
#include <QtCore/QRegularExpression>
#include <QtCore/QRegularExpressionMatch>
#include <QtCore/QSharedPointer>
#include <QtCore/QScopedPointer>
#include <QtCore/QTemporaryFile>
Expand Down Expand Up @@ -7917,9 +7919,10 @@ void tst_QNetworkReply::synchronousAuthenticationCache()
"Content-Type: text/plain\r\n"
"\r\n"
"auth";
QRegExp rx("Authorization: Basic ([^\r\n]*)\r\n");
if (rx.indexIn(receivedData) > 0) {
if (QByteArray::fromBase64(rx.cap(1).toLatin1()) == "login:password") {
QRegularExpression rx("Authorization: Basic ([^\r\n]*)\r\n");
QRegularExpressionMatch match = rx.match(receivedData);
if (match.hasMatch()) {
if (QByteArray::fromBase64(match.captured(1).toLatin1()) == "login:password") {
dataToTransmit =
"HTTP/1.0 200 OK\r\n"
"Content-Type: text/plain\r\n"
Expand Down

0 comments on commit 16cc3ea

Please sign in to comment.