diff options
-rw-r--r-- | src/corelib/io/qurl.cpp | 27 | ||||
-rw-r--r-- | tests/auto/qurl/tst_qurl.cpp | 3 |
2 files changed, 22 insertions, 8 deletions
diff --git a/src/corelib/io/qurl.cpp b/src/corelib/io/qurl.cpp index 076cc33f64..05d043e239 100644 --- a/src/corelib/io/qurl.cpp +++ b/src/corelib/io/qurl.cpp @@ -437,17 +437,19 @@ static bool QT_FASTCALL _unreserved(const char **ptr) } // scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." ) -static void QT_FASTCALL _scheme(const char **ptr, QUrlParseData *parseData) +static bool QT_FASTCALL _scheme(const char **ptr, QUrlParseData *parseData) { bool first = true; - + bool isSchemeValid = true; + parseData->scheme = *ptr; for (;;) { char ch = **ptr; if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z')) { ; - } else if (!first && ((ch >= '0' && ch <= '9') || ch == '+' || ch == '-' || ch == '.')) { - ; + } else if ((ch >= '0' && ch <= '9') || ch == '+' || ch == '-' || ch == '.') { + if (first) + isSchemeValid = false; } else { break; } @@ -457,11 +459,14 @@ static void QT_FASTCALL _scheme(const char **ptr, QUrlParseData *parseData) } if (**ptr != ':') { + isSchemeValid = true; *ptr = parseData->scheme; } else { parseData->schemeLength = *ptr - parseData->scheme; ++(*ptr); // skip ':' } + + return isSchemeValid; } // IPvFuture = "v" 1*HEXDIG "." 1*( unreserved / sub-delims / ":" ) @@ -3743,7 +3748,19 @@ void QUrlPrivate::parse(ParseOptions parseOptions) const #endif // optional scheme - _scheme(ptr, &parseData); + bool isSchemeValid = _scheme(ptr, &parseData); + + if (isSchemeValid == false) { + that->isValid = false; + char ch = *((*ptr)++); + that->errorInfo.setParams(*ptr, QT_TRANSLATE_NOOP(QUrl, "unexpected URL scheme"), + 0, ch); + QURL_SETFLAG(that->stateFlags, Validated | Parsed); +#if defined (QURL_DEBUG) + qDebug("QUrlPrivate::parse(), unrecognized: %c%s", ch, *ptr); +#endif + return; + } // hierpart _hierPart(ptr, &parseData); diff --git a/tests/auto/qurl/tst_qurl.cpp b/tests/auto/qurl/tst_qurl.cpp index 72ce3934ed..bc5a0af12f 100644 --- a/tests/auto/qurl/tst_qurl.cpp +++ b/tests/auto/qurl/tst_qurl.cpp @@ -2513,9 +2513,6 @@ void tst_QUrl::schemeValidator() void tst_QUrl::invalidSchemeValidator() { - // enable that test when QUrl is fixed - return; - // test that if scheme does not start with an ALPHA, QUrl::isValid() returns false { QUrl url("1http://qt.nokia.com", QUrl::StrictMode); |