Update QUrlPrivate::setScheme: EmptySchemeError never happens
authorThiago Macieira <thiago.macieira@intel.com>
Thu, 20 Sep 2012 10:54:38 +0000 (12:54 +0200)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Tue, 2 Oct 2012 20:34:42 +0000 (22:34 +0200)
As the comment says, an empty scheme is not permitted. However, if
that error were to happen, QUrl falls back to parsing the URI as an
"URI reference", starting with the path.

E.g., ":/foo" is a path of ":/foo", which will in turn trigger the
compound "colon before slash" error.

Also, we don't percent-decode in the scheme.

Change-Id: I438a61e17323c7722ddcc64792577a9ecb869c4b
Reviewed-by: Shane Kearns <shane.kearns@accenture.com>
Reviewed-by: David Faure <faure@kde.org>
src/corelib/io/qurl.cpp
src/corelib/io/qurl_p.h

index 0f8ed9f..3c82a26 100644 (file)
@@ -661,17 +661,17 @@ bool QUrlPrivate::setScheme(const QString &value, int len)
 {
     // schemes are strictly RFC-compliant:
     //    scheme        = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
-    // but we need to decode any percent-encoding sequences that fall on
-    // those characters
     // we also lowercase the scheme
 
+    // schemes in URLs are not allowed to be empty, but they can be in
+    // "Relative URIs" which QUrl also supports. QUrl::setScheme does
+    // not call us with len == 0, so this can only be from parse()
     scheme.clear();
-    sectionIsPresent |= Scheme;
-    sectionHasError |= Scheme; // assume it has errors, we'll clear before returning true
-    errorCode = SchemeEmptyError;
     if (len == 0)
         return false;
 
+    sectionIsPresent |= Scheme;
+
     // validate it:
     errorCode = InvalidSchemeError;
     int needsLowercasing = -1;
@@ -3413,8 +3413,6 @@ static QString errorMessage(QUrlPrivate::ErrorCode errorCode, QChar c)
         QString msg = QStringLiteral("Invalid scheme (character '%1' not permitted)");
         return msg.arg(c);
     }
-    case QUrlPrivate::SchemeEmptyError:
-        return QStringLiteral("Empty scheme");
 
     case QUrlPrivate::InvalidUserNameError:
         return QString(QStringLiteral("Invalid user name (character '%1' not permitted)"))
index 8c1e307..12ab0c7 100644 (file)
@@ -79,7 +79,6 @@ public:
     enum ErrorCode {
         // the high byte of the error code matches the Section
         InvalidSchemeError = Scheme << 8,
-        SchemeEmptyError,
 
         InvalidUserNameError = UserName << 8,