diff options
-rw-r--r-- | src/corelib/io/qurl.cpp | 75 | ||||
-rw-r--r-- | src/testlib/qtest.h | 2 | ||||
-rw-r--r-- | tests/auto/testlib/selftests/expected_datetime.lightxml | 4 | ||||
-rw-r--r-- | tests/auto/testlib/selftests/expected_datetime.txt | 4 | ||||
-rw-r--r-- | tests/auto/testlib/selftests/expected_datetime.xml | 4 | ||||
-rw-r--r-- | tests/auto/testlib/selftests/expected_datetime.xunitxml | 4 |
6 files changed, 64 insertions, 29 deletions
diff --git a/src/corelib/io/qurl.cpp b/src/corelib/io/qurl.cpp index 38eb613d74..0f8ed9fb17 100644 --- a/src/corelib/io/qurl.cpp +++ b/src/corelib/io/qurl.cpp @@ -3403,27 +3403,8 @@ QDebug operator<<(QDebug d, const QUrl &url) } #endif -/*! - \since 4.2 - - Returns a text string that explains why an URL is invalid in the case being; - otherwise returns an empty string. -*/ -QString QUrl::errorString() const +static QString errorMessage(QUrlPrivate::ErrorCode errorCode, QChar c) { - if (!d) - return QString(); - - QUrlPrivate::ErrorCode errorCode = d->validityError(); - if (errorCode == QUrlPrivate::NoError) - return QString(); - - // check if the error code matches a section with error - // unless it's a compound error (0x10000) - if ((d->sectionHasError & (errorCode >> 8)) == 0 && (errorCode & 0x10000) == 0) - return QString(); - - QChar c = d->errorSupplement; switch (errorCode) { case QUrlPrivate::NoError: return QString(); @@ -3444,7 +3425,7 @@ QString QUrl::errorString() const .arg(c); case QUrlPrivate::InvalidRegNameError: - if (d->errorSupplement) + if (!c.isNull()) return QString(QStringLiteral("Invalid hostname (character '%1' not permitted)")) .arg(c); else @@ -3482,6 +3463,58 @@ QString QUrl::errorString() const return QStringLiteral("<unknown error>"); } +static inline void appendComponentIfPresent(QString &msg, bool present, const char *componentName, + const QString &component) +{ + if (present) { + msg += QLatin1String(componentName); + msg += QLatin1Char('"'); + msg += component; + msg += QLatin1String("\","); + } +} + +/*! + \since 4.2 + + Returns a text string that explains why an URL is invalid in the case being; + otherwise returns an empty string. +*/ +QString QUrl::errorString() const +{ + if (!d) + return QString(); + + QUrlPrivate::ErrorCode errorCode = d->validityError(); + if (errorCode == QUrlPrivate::NoError) + return QString(); + + // check if the error code matches a section with error + // unless it's a compound error (0x10000) + if ((d->sectionHasError & (errorCode >> 8)) == 0 && (errorCode & 0x10000) == 0) + return QString(); + + QString msg = errorMessage(errorCode, d->errorSupplement); + msg += QLatin1Char(';'); + appendComponentIfPresent(msg, d->sectionIsPresent & QUrlPrivate::Scheme, + " scheme = ", d->scheme); + appendComponentIfPresent(msg, d->sectionIsPresent & QUrlPrivate::UserInfo, + " userinfo = ", userInfo()); + appendComponentIfPresent(msg, d->sectionIsPresent & QUrlPrivate::Host, + " host = ", d->host); + appendComponentIfPresent(msg, d->port != -1, + " port = ", QString::number(d->port)); + appendComponentIfPresent(msg, !d->path.isEmpty(), + " path = ", d->path); + appendComponentIfPresent(msg, d->sectionIsPresent & QUrlPrivate::Query, + " query = ", d->query); + appendComponentIfPresent(msg, d->sectionIsPresent & QUrlPrivate::Fragment, + " fragment = ", d->fragment); + if (msg.endsWith(QLatin1Char(','))) + msg.chop(1); + return msg; +} + /*! \typedef QUrl::DataPtr \internal diff --git a/src/testlib/qtest.h b/src/testlib/qtest.h index beb4ad59f6..a38b65671b 100644 --- a/src/testlib/qtest.h +++ b/src/testlib/qtest.h @@ -144,6 +144,8 @@ template<> inline char *toString(const QRectF &s) template<> inline char *toString(const QUrl &uri) { + if (!uri.isValid()) + return qstrdup(QByteArray("Invalid URL: " + uri.errorString().toLatin1()).constData()); return qstrdup(uri.toEncoded().constData()); } diff --git a/tests/auto/testlib/selftests/expected_datetime.lightxml b/tests/auto/testlib/selftests/expected_datetime.lightxml index 39af3a2fcf..d8acae9c26 100644 --- a/tests/auto/testlib/selftests/expected_datetime.lightxml +++ b/tests/auto/testlib/selftests/expected_datetime.lightxml @@ -20,12 +20,12 @@ <DataTag><![CDATA[empty rhs]]></DataTag> <Description><![CDATA[Compared values are not the same Actual (operandA): http://example.com - Expected (operandB): ]]></Description> + Expected (operandB): Invalid URL: ]]></Description> </Incident> <Incident type="fail" file="/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/datetime/tst_datetime.cpp" line="74"> <DataTag><![CDATA[empty lhs]]></DataTag> <Description><![CDATA[Compared values are not the same - Actual (operandA): + Actual (operandA): Invalid URL: Expected (operandB): http://example.com]]></Description> </Incident> <Incident type="pass" file="" line="0"> diff --git a/tests/auto/testlib/selftests/expected_datetime.txt b/tests/auto/testlib/selftests/expected_datetime.txt index 6bd4103284..6e82bddda7 100644 --- a/tests/auto/testlib/selftests/expected_datetime.txt +++ b/tests/auto/testlib/selftests/expected_datetime.txt @@ -8,10 +8,10 @@ FAIL! : tst_DateTime::dateTime() Compared values are not the same PASS : tst_DateTime::qurl(empty urls) FAIL! : tst_DateTime::qurl(empty rhs) Compared values are not the same Actual (operandA): http://example.com - Expected (operandB): + Expected (operandB): Invalid URL: Loc: [/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/datetime/tst_datetime.cpp(41)] FAIL! : tst_DateTime::qurl(empty lhs) Compared values are not the same - Actual (operandA): + Actual (operandA): Invalid URL: Expected (operandB): http://example.com Loc: [/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/datetime/tst_datetime.cpp(41)] PASS : tst_DateTime::qurl(same urls) diff --git a/tests/auto/testlib/selftests/expected_datetime.xml b/tests/auto/testlib/selftests/expected_datetime.xml index ebdd5f4650..d7c9afabee 100644 --- a/tests/auto/testlib/selftests/expected_datetime.xml +++ b/tests/auto/testlib/selftests/expected_datetime.xml @@ -22,12 +22,12 @@ <DataTag><![CDATA[empty rhs]]></DataTag> <Description><![CDATA[Compared values are not the same Actual (operandA): http://example.com - Expected (operandB): ]]></Description> + Expected (operandB): Invalid URL: ]]></Description> </Incident> <Incident type="fail" file="/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/datetime/tst_datetime.cpp" line="74"> <DataTag><![CDATA[empty lhs]]></DataTag> <Description><![CDATA[Compared values are not the same - Actual (operandA): + Actual (operandA): Invalid URL: Expected (operandB): http://example.com]]></Description> </Incident> <Incident type="pass" file="" line="0"> diff --git a/tests/auto/testlib/selftests/expected_datetime.xunitxml b/tests/auto/testlib/selftests/expected_datetime.xunitxml index b6bb600251..af0e4db7e8 100644 --- a/tests/auto/testlib/selftests/expected_datetime.xunitxml +++ b/tests/auto/testlib/selftests/expected_datetime.xunitxml @@ -13,9 +13,9 @@ <testcase result="fail" name="qurl"> <failure tag="empty rhs" message="Compared values are not the same Actual (operandA): http://example.com - Expected (operandB): " result="fail"/> + Expected (operandB): Invalid URL: " result="fail"/> <failure tag="empty lhs" message="Compared values are not the same - Actual (operandA): + Actual (operandA): Invalid URL: Expected (operandB): http://example.com" result="fail"/> </testcase> <testcase result="pass" name="cleanupTestCase"/> |