<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[204431] trunk</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/204431">204431</a></dd>
<dt>Author</dt> <dd>achristensen@apple.com</dd>
<dt>Date</dt> <dd>2016-08-12 16:12:46 -0700 (Fri, 12 Aug 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>Make URLParser work with URLs missing URL parts
https://bugs.webkit.org/show_bug.cgi?id=160824

Reviewed by Brady Eidson.

Source/WebCore:

My initial implementation of URLParser didn't work correctly with URLs missing parts,
like a URL with no fragment, or a URL with no query.  This fixes and tests parsing such URLS.
Covered by new API tests.

* platform/URLParser.cpp:
(WebCore::URLParser::parse):
(WebCore::URLParser::allValuesEqual):
* platform/URLParser.h:
(WebCore::URLParser::parse):

Tools:

* TestWebKitAPI/Tests/WebCore/URLParser.cpp:
(TestWebKitAPI::s):
(TestWebKitAPI::checkURL):
(TestWebKitAPI::TEST_F):
(TestWebKitAPI::eq): Deleted.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreplatformURLParsercpp">trunk/Source/WebCore/platform/URLParser.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformURLParserh">trunk/Source/WebCore/platform/URLParser.h</a></li>
<li><a href="#trunkToolsChangeLog">trunk/Tools/ChangeLog</a></li>
<li><a href="#trunkToolsTestWebKitAPITestsWebCoreURLParsercpp">trunk/Tools/TestWebKitAPI/Tests/WebCore/URLParser.cpp</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (204430 => 204431)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2016-08-12 23:08:40 UTC (rev 204430)
+++ trunk/Source/WebCore/ChangeLog        2016-08-12 23:12:46 UTC (rev 204431)
</span><span class="lines">@@ -1,3 +1,20 @@
</span><ins>+2016-08-12  Alex Christensen  &lt;achristensen@webkit.org&gt;
+
+        Make URLParser work with URLs missing URL parts
+        https://bugs.webkit.org/show_bug.cgi?id=160824
+
+        Reviewed by Brady Eidson.
+
+        My initial implementation of URLParser didn't work correctly with URLs missing parts,
+        like a URL with no fragment, or a URL with no query.  This fixes and tests parsing such URLS.
+        Covered by new API tests.
+
+        * platform/URLParser.cpp:
+        (WebCore::URLParser::parse):
+        (WebCore::URLParser::allValuesEqual):
+        * platform/URLParser.h:
+        (WebCore::URLParser::parse):
+
</ins><span class="cx"> 2016-08-12  Johan K. Jensen  &lt;johan_jensen@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Rename DocumentLoadTiming and ResourceLoadTiming
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformURLParsercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/URLParser.cpp (204430 => 204431)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/URLParser.cpp        2016-08-12 23:08:40 UTC (rev 204430)
+++ trunk/Source/WebCore/platform/URLParser.cpp        2016-08-12 23:12:46 UTC (rev 204431)
</span><span class="lines">@@ -31,7 +31,6 @@
</span><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><del>-// 1. Infrastructure
</del><span class="cx"> static bool isC0Control(const StringView::CodePoints::Iterator&amp; c) { return *c &lt;= 0x001F; }
</span><span class="cx"> static bool isC0ControlOrSpace(const StringView::CodePoints::Iterator&amp; c) { return isC0Control(c) || *c == 0x0020; }
</span><span class="cx"> static bool isTabOrNewline(const StringView::CodePoints::Iterator&amp; c) { return *c == 0x0009 || *c == 0x000A || *c == 0x000D; }
</span><span class="lines">@@ -39,7 +38,6 @@
</span><span class="cx"> static bool isASCIIAlpha(const StringView::CodePoints::Iterator&amp; c) { return (*c &gt;= 0x0041 &amp;&amp; *c &lt;= 0x005A) || (*c &gt;= 0x0061 &amp;&amp; *c &lt;= 0x007A); }
</span><span class="cx"> static bool isASCIIAlphanumeric(const StringView::CodePoints::Iterator&amp; c) { return isASCIIDigit(c) || isASCIIAlpha(c); }
</span><span class="cx">     
</span><del>-// 4. URLs
</del><span class="cx"> static bool isSpecialScheme(const String&amp; scheme)
</span><span class="cx"> {
</span><span class="cx">     return scheme == &quot;ftp&quot;
</span><span class="lines">@@ -65,7 +63,7 @@
</span><span class="cx">     enum class State : uint8_t {
</span><span class="cx">         SchemeStart,
</span><span class="cx">         Scheme,
</span><del>-        SchemeEndCheckForSlashes, // Scheme state steps 2. 8.
</del><ins>+        SchemeEndCheckForSlashes,
</ins><span class="cx">         NoScheme,
</span><span class="cx">         SpecialRelativeOrAuthority,
</span><span class="cx">         PathOrAuthority,
</span><span class="lines">@@ -113,6 +111,7 @@
</span><span class="cx">             else if (*c == ':') {
</span><span class="cx">                 url.m_schemeEnd = buffer.length();
</span><span class="cx">                 String urlScheme = buffer.toString(); // FIXME: Find a way to do this without shrinking the buffer.
</span><ins>+                url.m_protocolIsInHTTPFamily = urlScheme == &quot;http&quot; || urlScheme == &quot;https&quot;;
</ins><span class="cx">                 if (urlScheme == &quot;file&quot;)
</span><span class="cx">                     state = State::File;
</span><span class="cx">                 else if (isSpecialScheme(urlScheme)) {
</span><span class="lines">@@ -271,9 +270,11 @@
</span><span class="cx">         case State::Path:
</span><span class="cx">             LOG_STATE(&quot;Path&quot;);
</span><span class="cx">             if (*c == '/') {
</span><ins>+                buffer.append('/');
+                url.m_pathAfterLastSlash = buffer.length();
</ins><span class="cx">                 ++c;
</span><span class="cx">                 if (c == end)
</span><del>-                    return Nullopt;
</del><ins>+                    break;
</ins><span class="cx">                 if (*c == '.') {
</span><span class="cx">                     ++c;
</span><span class="cx">                     if (c == end)
</span><span class="lines">@@ -282,7 +283,6 @@
</span><span class="cx">                         notImplemented();
</span><span class="cx">                     notImplemented();
</span><span class="cx">                 }
</span><del>-                buffer.append('/');
</del><span class="cx">             } else if (*c == '?') {
</span><span class="cx">                 url.m_pathEnd = buffer.length();
</span><span class="cx">                 state = State::Query;
</span><span class="lines">@@ -318,8 +318,78 @@
</span><span class="cx">             break;
</span><span class="cx">         }
</span><span class="cx">     }
</span><ins>+    
+    switch (state) {
+    case State::SchemeStart:
+    case State::Scheme:
+    case State::SchemeEndCheckForSlashes:
+    case State::NoScheme:
+    case State::SpecialRelativeOrAuthority:
+    case State::PathOrAuthority:
+    case State::Relative:
+    case State::RelativeSlash:
+    case State::SpecialAuthoritySlashes:
+    case State::SpecialAuthorityIgnoreSlashes:
+    case State::Authority:
+        break;
+    case State::Host:
+    case State::Hostname:
+        url.m_hostEnd = buffer.length();
+        url.m_portEnd = url.m_hostEnd;
+        buffer.append('/');
+        url.m_pathEnd = url.m_hostEnd + 1;
+        url.m_pathAfterLastSlash = url.m_pathEnd;
+        url.m_queryEnd = url.m_pathEnd;
+        url.m_fragmentEnd = url.m_pathEnd;
+        break;
+    case State::Port:
+        url.m_portEnd = buffer.length();
+        buffer.append('/');
+        url.m_pathEnd = url.m_portEnd + 1;
+        url.m_pathAfterLastSlash = url.m_pathEnd;
+        url.m_queryEnd = url.m_pathEnd;
+        url.m_fragmentEnd = url.m_pathEnd;
+        break;
+    case State::File:
+    case State::FileSlash:
+    case State::FileHost:
+    case State::PathStart:
+    case State::Path:
+        url.m_pathEnd = buffer.length();
+        url.m_queryEnd = url.m_pathEnd;
+        url.m_fragmentEnd = url.m_pathEnd;
+        break;
+    case State::CannotBeABaseURLPath:
+        break;
+    case State::Query:
+        url.m_queryEnd = buffer.length();
+        url.m_fragmentEnd = url.m_queryEnd;
+        break;
+    case State::Fragment:
+        url.m_fragmentEnd = buffer.length();
+        break;
+    }
+
</ins><span class="cx">     url.m_string = buffer.toString();
</span><ins>+    url.m_isValid = true;
</ins><span class="cx">     return url;
</span><span class="cx"> }
</span><del>-    
</del><ins>+
+bool URLParser::allValuesEqual(const URL&amp; a, const URL&amp; b)
+{
+    return a.m_string == b.m_string
+        &amp;&amp; a.m_isValid == b.m_isValid
+        &amp;&amp; a.m_protocolIsInHTTPFamily == b.m_protocolIsInHTTPFamily
+        &amp;&amp; a.m_schemeEnd == b.m_schemeEnd
+        &amp;&amp; a.m_userStart == b.m_userStart
+        &amp;&amp; a.m_userEnd == b.m_userEnd
+        &amp;&amp; a.m_passwordEnd == b.m_passwordEnd
+        &amp;&amp; a.m_hostEnd == b.m_hostEnd
+        &amp;&amp; a.m_portEnd == b.m_portEnd
+        &amp;&amp; a.m_pathAfterLastSlash == b.m_pathAfterLastSlash
+        &amp;&amp; a.m_pathEnd == b.m_pathEnd
+        &amp;&amp; a.m_queryEnd == b.m_queryEnd
+        &amp;&amp; a.m_fragmentEnd == b.m_fragmentEnd;
+}
+
</ins><span class="cx"> } // namespace WebCore
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformURLParserh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/URLParser.h (204430 => 204431)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/URLParser.h        2016-08-12 23:08:40 UTC (rev 204430)
+++ trunk/Source/WebCore/platform/URLParser.h        2016-08-12 23:12:46 UTC (rev 204431)
</span><span class="lines">@@ -34,6 +34,7 @@
</span><span class="cx"> class URLParser {
</span><span class="cx"> public:
</span><span class="cx">     WEBCORE_EXPORT static Optional&lt;URL&gt; parse(const String&amp;, const URL&amp; = { }, const TextEncoding&amp; = UTF8Encoding());
</span><ins>+    WEBCORE_EXPORT static bool allValuesEqual(const URL&amp;, const URL&amp;);
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkToolsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Tools/ChangeLog (204430 => 204431)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/ChangeLog        2016-08-12 23:08:40 UTC (rev 204430)
+++ trunk/Tools/ChangeLog        2016-08-12 23:12:46 UTC (rev 204431)
</span><span class="lines">@@ -1,3 +1,16 @@
</span><ins>+2016-08-12  Alex Christensen  &lt;achristensen@webkit.org&gt;
+
+        Make URLParser work with URLs missing URL parts
+        https://bugs.webkit.org/show_bug.cgi?id=160824
+
+        Reviewed by Brady Eidson.
+
+        * TestWebKitAPI/Tests/WebCore/URLParser.cpp:
+        (TestWebKitAPI::s):
+        (TestWebKitAPI::checkURL):
+        (TestWebKitAPI::TEST_F):
+        (TestWebKitAPI::eq): Deleted.
+
</ins><span class="cx"> 2016-08-12  John Wilander  &lt;wilander@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Add HashCountedSet API tests to TestWTFLibrary target
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPITestsWebCoreURLParsercpp"></a>
<div class="modfile"><h4>Modified: trunk/Tools/TestWebKitAPI/Tests/WebCore/URLParser.cpp (204430 => 204431)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/Tests/WebCore/URLParser.cpp        2016-08-12 23:08:40 UTC (rev 204430)
+++ trunk/Tools/TestWebKitAPI/Tests/WebCore/URLParser.cpp        2016-08-12 23:12:46 UTC (rev 204431)
</span><span class="lines">@@ -47,25 +47,45 @@
</span><span class="cx">     String path;
</span><span class="cx">     String query;
</span><span class="cx">     String fragment;
</span><ins>+    String string;
</ins><span class="cx"> };
</span><ins>+
+static const char* s(const String&amp; s) { return s.utf8().data(); }
+static void checkURL(const String&amp; urlString, const ExpectedParts&amp; parts)
+{
+    auto url = URLParser::parse(urlString);
+    EXPECT_STREQ(s(parts.protocol), s(url-&gt;protocol()));
+    EXPECT_STREQ(s(parts.user), s(url-&gt;user()));
+    EXPECT_STREQ(s(parts.password), s(url-&gt;pass()));
+    EXPECT_STREQ(s(parts.host), s(url-&gt;host()));
+    EXPECT_EQ(parts.port, url-&gt;port());
+    EXPECT_STREQ(s(parts.path), s(url-&gt;path()));
+    EXPECT_STREQ(s(parts.query), s(url-&gt;query()));
+    EXPECT_STREQ(s(parts.fragment), s(url-&gt;fragmentIdentifier()));
+    EXPECT_STREQ(s(parts.string), s(url-&gt;string()));
</ins><span class="cx">     
</span><del>-static void eq(const String&amp; s1, const String&amp; s2) { EXPECT_STREQ(s1.utf8().data(), s2.utf8().data()); }
-static void checkURL(const URL&amp; url, const ExpectedParts&amp; parts)
-{
-    eq(url.protocol(), parts.protocol);
-    eq(url.user(), parts.user);
-    eq(url.pass(), parts.password);
-    eq(url.host(), parts.host);
-    EXPECT_EQ(url.port(), parts.port);
-    eq(url.path(), parts.path);
-    eq(url.query(), parts.query);
-    eq(url.fragmentIdentifier(), parts.fragment);
</del><ins>+    auto oldURL = URL(URL(), urlString);
+    EXPECT_STREQ(s(parts.protocol), s(oldURL.protocol()));
+    EXPECT_STREQ(s(parts.user), s(oldURL.user()));
+    EXPECT_STREQ(s(parts.password), s(oldURL.pass()));
+    EXPECT_STREQ(s(parts.host), s(oldURL.host()));
+    EXPECT_EQ(parts.port, oldURL.port());
+    EXPECT_STREQ(s(parts.path), s(oldURL.path()));
+    EXPECT_STREQ(s(parts.query), s(oldURL.query()));
+    EXPECT_STREQ(s(parts.fragment), s(oldURL.fragmentIdentifier()));
+    EXPECT_STREQ(s(parts.string), s(oldURL.string()));
+    
+    EXPECT_TRUE(URLParser::allValuesEqual(url.value(), oldURL));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> TEST_F(URLParserTest, Parse)
</span><span class="cx"> {
</span><del>-    auto url = URLParser::parse(&quot;http://user:pass@webkit.org:123/path?query#fragment&quot;);
-    checkURL(url.value(), {&quot;http&quot;, &quot;user&quot;, &quot;pass&quot;, &quot;webkit.org&quot;, 123, &quot;/path&quot;, &quot;query&quot;, &quot;fragment&quot;});
</del><ins>+    checkURL(&quot;http://user:pass@webkit.org:123/path?query#fragment&quot;, {&quot;http&quot;, &quot;user&quot;, &quot;pass&quot;, &quot;webkit.org&quot;, 123, &quot;/path&quot;, &quot;query&quot;, &quot;fragment&quot;, &quot;http://user:pass@webkit.org:123/path?query#fragment&quot;});
+    checkURL(&quot;http://user:pass@webkit.org:123/path?query&quot;, {&quot;http&quot;, &quot;user&quot;, &quot;pass&quot;, &quot;webkit.org&quot;, 123, &quot;/path&quot;, &quot;query&quot;, &quot;&quot;, &quot;http://user:pass@webkit.org:123/path?query&quot;});
+    checkURL(&quot;http://user:pass@webkit.org:123/path&quot;, {&quot;http&quot;, &quot;user&quot;, &quot;pass&quot;, &quot;webkit.org&quot;, 123, &quot;/path&quot;, &quot;&quot;, &quot;&quot;, &quot;http://user:pass@webkit.org:123/path&quot;});
+    checkURL(&quot;http://user:pass@webkit.org:123/&quot;, {&quot;http&quot;, &quot;user&quot;, &quot;pass&quot;, &quot;webkit.org&quot;, 123, &quot;/&quot;, &quot;&quot;, &quot;&quot;, &quot;http://user:pass@webkit.org:123/&quot;});
+    checkURL(&quot;http://user:pass@webkit.org:123&quot;, {&quot;http&quot;, &quot;user&quot;, &quot;pass&quot;, &quot;webkit.org&quot;, 123, &quot;/&quot;, &quot;&quot;, &quot;&quot;, &quot;http://user:pass@webkit.org:123/&quot;});
+    checkURL(&quot;http://user:pass@webkit.org&quot;, {&quot;http&quot;, &quot;user&quot;, &quot;pass&quot;, &quot;webkit.org&quot;, 0, &quot;/&quot;, &quot;&quot;, &quot;&quot;, &quot;http://user:pass@webkit.org/&quot;});
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> } // namespace TestWebKitAPI
</span></span></pre>
</div>
</div>

</body>
</html>