Make QUrl always lowercase the scheme().
authorDavid Faure <faure@kde.org>
Tue, 24 Jan 2012 13:51:51 +0000 (14:51 +0100)
committerQt by Nokia <qt-info@nokia.com>
Tue, 24 Jan 2012 14:27:08 +0000 (15:27 +0100)
URL schemes can only contain alphanumeric characters and all
protocols specify that they are case-insensitive. So instead
of doing case-insensitive comparison everywhere and then get
it wrong sometimes, better to lower-case it here.

Change-Id: I61f51a3f4c85b90af1586ebcf69608987fbe2ec3
Reviewed-by: Jonas Gastal <jgastal@profusion.mobi>
Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
src/corelib/io/qurl.cpp
tests/auto/corelib/io/qurl/tst_qurl.cpp

index 2c75ac3..9856d5d 100644 (file)
@@ -3880,7 +3880,7 @@ void QUrlPrivate::parse(ParseOptions parseOptions) const
 
         if (parseData.scheme) {
             QByteArray s(parseData.scheme, parseData.schemeLength);
-            that->scheme = fromPercentEncodingMutable(&s);
+            that->scheme = fromPercentEncodingMutable(&s).toLower();
         }
 
         that->setEncodedUserInfo(&parseData);
@@ -4041,7 +4041,6 @@ const QByteArray &QUrlPrivate::normalized() const
     QURL_SETFLAG(that->stateFlags, QUrlPrivate::Normalized);
 
     QUrlPrivate tmp = *this;
-    tmp.scheme = tmp.scheme.toLower();
     tmp.host = tmp.canonicalHost();
 
     // ensure the encoded and normalized parts of the URL
@@ -4467,13 +4466,15 @@ void QUrl::setScheme(const QString &scheme)
     detach();
     QURL_UNSETFLAG(d->stateFlags, QUrlPrivate::Validated | QUrlPrivate::Normalized);
 
-    d->scheme = scheme;
+    d->scheme = scheme.toLower();
 }
 
 /*!
     Returns the scheme of the URL. If an empty string is returned,
     this means the scheme is undefined and the URL is then relative.
 
+    The returned scheme is always lowercase, for convenience.
+
     \sa setScheme(), isRelative()
 */
 QString QUrl::scheme() const
index f9dcb84..2f53367 100644 (file)
@@ -375,7 +375,7 @@ void tst_QUrl::setUrl()
     {
         QUrl url("hTTp://www.foo.bar:80");
         QVERIFY(url.isValid());
-        QCOMPARE(url.scheme(), QString::fromLatin1("hTTp"));
+        QCOMPARE(url.scheme(), QString::fromLatin1("http"));
         QCOMPARE(url.path(), QString());
         QVERIFY(url.encodedQuery().isEmpty());
         QVERIFY(url.userInfo().isEmpty());
@@ -385,7 +385,7 @@ void tst_QUrl::setUrl()
         QCOMPARE(url.port(), 80);
 
         QUrl url2("//www1.foo.bar");
-        QCOMPARE(url.resolved(url2).toString(), QString::fromLatin1("hTTp://www1.foo.bar"));
+        QCOMPARE(url.resolved(url2).toString(), QString::fromLatin1("http://www1.foo.bar"));
     }
 
     {