summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorSteve Block <steveblock@google.com>2012-03-27 18:35:51 +0100
committerSteve Block <steveblock@google.com>2012-03-28 16:43:36 +0100
commitdb951b2c4c8fce1304a13d97dec4ae14be629380 (patch)
treefceec9642036dfb4a15cda37d486bb864794535b /Source
parent32399fa13ad918dafbbb5dac3e65584be87a459a (diff)
downloadexternal_webkit-db951b2c4c8fce1304a13d97dec4ae14be629380.zip
external_webkit-db951b2c4c8fce1304a13d97dec4ae14be629380.tar.gz
external_webkit-db951b2c4c8fce1304a13d97dec4ae14be629380.tar.bz2
Cherry-pick WebKit change r84762 to fix URL canonicalization
This is to make sure URL parsing behaviour is up-to-date prior to fixing window.location. See bug for details. Note that the 'http:example.com/' test case in fast/url/standard-url.html fails with DRT2 because of an assumption in the test that it is served as a file scheme URL. See http://trac.webkit.org/changeset/84762 Bug: 2159848 Change-Id: Ie680debcad3d285efd40134932b72d429c0d2222
Diffstat (limited to 'Source')
-rw-r--r--Source/WebCore/platform/KURL.cpp31
1 files changed, 26 insertions, 5 deletions
diff --git a/Source/WebCore/platform/KURL.cpp b/Source/WebCore/platform/KURL.cpp
index 88ad3d9..fd24e3d 100644
--- a/Source/WebCore/platform/KURL.cpp
+++ b/Source/WebCore/platform/KURL.cpp
@@ -1137,6 +1137,23 @@ static inline bool hostPortIsEmptyButCredentialsArePresent(int hostStart, int po
return userEndChar == '@' && hostStart == portEnd;
}
+static bool isNonFileHierarchicalScheme(const char* scheme, size_t schemeLength)
+{
+ switch (schemeLength) {
+ case 2:
+ return equal("ws", 2, scheme, schemeLength);
+ case 3:
+ return equal("ftp", 3, scheme, schemeLength) || equal("wss", 3, scheme, schemeLength);
+ case 4:
+ return equal("http", 4, scheme, schemeLength);
+ case 5:
+ return equal("https", 5, scheme, schemeLength);
+ case 6:
+ return equal("gopher", 6, scheme, schemeLength);
+ }
+ return false;
+}
+
void KURL::parse(const char* url, const String* originalString)
{
if (!url || url[0] == '\0') {
@@ -1173,6 +1190,7 @@ void KURL::parse(const char* url, const String* originalString)
int portEnd;
bool hierarchical = url[schemeEnd + 1] == '/';
+ bool hasSecondSlash = hierarchical && url[schemeEnd + 2] == '/';
bool isFile = schemeEnd == 4
&& matchLetter(url[0], 'f')
@@ -1186,12 +1204,15 @@ void KURL::parse(const char* url, const String* originalString)
&& matchLetter(url[3], 'p')
&& (url[4] == ':' || (matchLetter(url[4], 's') && url[5] == ':'));
- if (hierarchical && url[schemeEnd + 2] == '/') {
+ if ((hierarchical && hasSecondSlash) || isNonFileHierarchicalScheme(url, schemeEnd)) {
// The part after the scheme is either a net_path or an abs_path whose first path segment is empty.
// Attempt to find an authority.
-
// FIXME: Authority characters may be scanned twice, and it would be nice to be faster.
- userStart += 2;
+
+ if (hierarchical)
+ userStart++;
+ if (hasSecondSlash)
+ userStart++;
userEnd = userStart;
int colonPos = 0;
@@ -1394,8 +1415,8 @@ void KURL::parse(const char* url, const String* originalString)
m_userStart = m_userEnd = m_passwordEnd = m_hostEnd = m_portEnd = p - buffer.data();
// For canonicalization, ensure we have a '/' for no path.
- // Do this only for hierarchical URL with protocol http or https.
- if (m_protocolInHTTPFamily && hierarchical && pathEnd == pathStart)
+ // Do this only for URL with protocol http or https.
+ if (m_protocolInHTTPFamily && pathEnd == pathStart)
*p++ = '/';
// add path, escaping bad characters