summaryrefslogtreecommitdiffstats
path: root/WebCore/platform/KURL.cpp
diff options
context:
space:
mode:
authorFeng Qian <>2009-04-10 18:11:29 -0700
committerThe Android Open Source Project <initial-contribution@android.com>2009-04-10 18:11:29 -0700
commit8f72e70a9fd78eec56623b3a62e68f16b7b27e28 (patch)
tree181bf9a400c30a1bf34ea6d72560e8d00111d549 /WebCore/platform/KURL.cpp
parent7ed56f225e0ade046e1c2178977f72b2d896f196 (diff)
downloadexternal_webkit-8f72e70a9fd78eec56623b3a62e68f16b7b27e28.zip
external_webkit-8f72e70a9fd78eec56623b3a62e68f16b7b27e28.tar.gz
external_webkit-8f72e70a9fd78eec56623b3a62e68f16b7b27e28.tar.bz2
AI 145796: Land the WebKit merge @r42026.
Automated import of CL 145796
Diffstat (limited to 'WebCore/platform/KURL.cpp')
-rw-r--r--WebCore/platform/KURL.cpp37
1 files changed, 25 insertions, 12 deletions
diff --git a/WebCore/platform/KURL.cpp b/WebCore/platform/KURL.cpp
index 6fcb9b9..6901782 100644
--- a/WebCore/platform/KURL.cpp
+++ b/WebCore/platform/KURL.cpp
@@ -289,6 +289,7 @@ inline bool KURL::protocolIs(const String& string, const char* protocol)
void KURL::invalidate()
{
m_isValid = false;
+ m_protocolInHTTPFamily = false;
m_schemeEnd = 0;
m_userStart = 0;
m_userEnd = 0;
@@ -604,6 +605,11 @@ bool KURL::hasRef() const
return m_fragmentEnd != m_queryEnd;
}
+String KURL::baseAsString() const
+{
+ return m_string.left(m_pathAfterLastSlash);
+}
+
#ifdef NDEBUG
static inline void assertProtocolIsGood(const char*)
@@ -638,7 +644,10 @@ bool KURL::protocolIs(const char* protocol) const
String KURL::query() const
{
- return m_string.substring(m_pathEnd, m_queryEnd - m_pathEnd);
+ if (m_queryEnd == m_pathEnd)
+ return String();
+
+ return m_string.substring(m_pathEnd + 1, m_queryEnd - (m_pathEnd + 1));
}
String KURL::path() const
@@ -677,13 +686,13 @@ void KURL::setPort(unsigned short i)
if (!m_isValid)
return;
- // FIXME: Non-ASCII characters must be encoded and escaped to match parse() expectations,
- // and to avoid changing more than just the port.
-
- bool colonNeeded = m_portEnd == m_hostEnd;
- int portStart = (colonNeeded ? m_hostEnd : m_hostEnd + 1);
+ if (i) {
+ bool colonNeeded = m_portEnd == m_hostEnd;
+ int portStart = (colonNeeded ? m_hostEnd : m_hostEnd + 1);
- parse(m_string.left(portStart) + (colonNeeded ? ":" : "") + String::number(i) + m_string.substring(m_portEnd));
+ parse(m_string.left(portStart) + (colonNeeded ? ":" : "") + String::number(i) + m_string.substring(m_portEnd));
+ } else
+ parse(m_string.left(m_hostEnd) + m_string.substring(m_portEnd));
}
void KURL::setHostAndPort(const String& hostAndPort)
@@ -822,7 +831,11 @@ String KURL::prettyURL() const
}
append(result, path());
- append(result, query());
+
+ if (m_pathEnd != m_queryEnd) {
+ result.append('?');
+ append(result, query());
+ }
if (m_fragmentEnd != m_queryEnd) {
result.append('#');
@@ -1047,7 +1060,7 @@ void KURL::parse(const char* url, const String* originalString)
&& matchLetter(url[2], 'l')
&& matchLetter(url[3], 'e');
- bool isHTTPorHTTPS = matchLetter(url[0], 'h')
+ m_protocolInHTTPFamily = matchLetter(url[0], 'h')
&& matchLetter(url[1], 't')
&& matchLetter(url[2], 't')
&& matchLetter(url[3], 'p')
@@ -1129,7 +1142,7 @@ void KURL::parse(const char* url, const String* originalString)
return;
}
- if (userStart == portEnd && !isHTTPorHTTPS && !isFile) {
+ if (userStart == portEnd && !m_protocolInHTTPFamily && !isFile) {
// No authority found, which means that this is not a net_path, but rather an abs_path whose first two
// path segments are empty. For file, http and https only, an empty authority is allowed.
userStart -= 2;
@@ -1253,7 +1266,7 @@ void KURL::parse(const char* url, const String* originalString)
// For canonicalization, ensure we have a '/' for no path.
// Only do this for http and https.
- if (isHTTPorHTTPS && pathEnd - pathStart == 0)
+ if (m_protocolInHTTPFamily && pathEnd - pathStart == 0)
*p++ = '/';
// add path, escaping bad characters
@@ -1291,7 +1304,7 @@ void KURL::parse(const char* url, const String* originalString)
// If we didn't end up actually changing the original string and
// it was already in a String, reuse it to avoid extra allocation.
- if (originalString && strncmp(buffer.data(), url, m_fragmentEnd) == 0)
+ if (originalString && originalString->length() == static_cast<unsigned>(m_fragmentEnd) && strncmp(buffer.data(), url, m_fragmentEnd) == 0)
m_string = *originalString;
else
m_string = String(buffer.data(), m_fragmentEnd);