<!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>[205493] 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/205493">205493</a></dd>
<dt>Author</dt> <dd>achristensen@apple.com</dd>
<dt>Date</dt> <dd>2016-09-06 11:16:07 -0700 (Tue, 06 Sep 2016)</dd>
</dl>
<h3>Log Message</h3>
<pre>Implement relative file urls and begin implementing character encoding in URLParser
https://bugs.webkit.org/show_bug.cgi?id=161618
Reviewed by Tim Horton.
Source/WebCore:
Covered by new API tests.
Also, this is a significant step towards passing the URL web platform tests when using the URLParser,
which is still off by default.
* platform/URLParser.cpp:
(WebCore::isInSimpleEncodeSet):
(WebCore::isInDefaultEncodeSet):
(WebCore::isInUserInfoEncodeSet):
(WebCore::isInvalidDomainCharacter):
(WebCore::shouldCopyFileURL):
(WebCore::percentEncode):
(WebCore::utf8PercentEncode):
(WebCore::encodeQuery):
(WebCore::isDefaultPort):
(WebCore::isPercentEncodedDot):
(WebCore::URLParser::parse):
(WebCore::percentDecode):
(WebCore::domainToASCII):
(WebCore::hasInvalidDomainCharacter):
(WebCore::URLParser::parsePort):
(WebCore::URLParser::parseHost):
(WebCore::isTabOrNewline): Deleted.
* platform/URLParser.h:
Tools:
* TestWebKitAPI/Tests/WebCore/URLParser.cpp:
(TestWebKitAPI::TEST_F):</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 (205492 => 205493)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2016-09-06 18:02:28 UTC (rev 205492)
+++ trunk/Source/WebCore/ChangeLog        2016-09-06 18:16:07 UTC (rev 205493)
</span><span class="lines">@@ -1,3 +1,34 @@
</span><ins>+2016-09-05 Alex Christensen <achristensen@webkit.org>
+
+ Implement relative file urls and begin implementing character encoding in URLParser
+ https://bugs.webkit.org/show_bug.cgi?id=161618
+
+ Reviewed by Tim Horton.
+
+ Covered by new API tests.
+ Also, this is a significant step towards passing the URL web platform tests when using the URLParser,
+ which is still off by default.
+
+ * platform/URLParser.cpp:
+ (WebCore::isInSimpleEncodeSet):
+ (WebCore::isInDefaultEncodeSet):
+ (WebCore::isInUserInfoEncodeSet):
+ (WebCore::isInvalidDomainCharacter):
+ (WebCore::shouldCopyFileURL):
+ (WebCore::percentEncode):
+ (WebCore::utf8PercentEncode):
+ (WebCore::encodeQuery):
+ (WebCore::isDefaultPort):
+ (WebCore::isPercentEncodedDot):
+ (WebCore::URLParser::parse):
+ (WebCore::percentDecode):
+ (WebCore::domainToASCII):
+ (WebCore::hasInvalidDomainCharacter):
+ (WebCore::URLParser::parsePort):
+ (WebCore::URLParser::parseHost):
+ (WebCore::isTabOrNewline): Deleted.
+ * platform/URLParser.h:
+
</ins><span class="cx"> 2016-09-06 Daniel Bates <dabates@apple.com>
</span><span class="cx">
</span><span class="cx"> Fix the Apple-internal build following <https://trac.webkit.org/changeset/205488>
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformURLParsercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/URLParser.cpp (205492 => 205493)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/URLParser.cpp        2016-09-06 18:02:28 UTC (rev 205492)
+++ trunk/Source/WebCore/platform/URLParser.cpp        2016-09-06 18:16:07 UTC (rev 205493)
</span><span class="lines">@@ -28,7 +28,10 @@
</span><span class="cx">
</span><span class="cx"> #include "Logging.h"
</span><span class="cx"> #include <array>
</span><ins>+#include <wtf/HashMap.h>
+#include <wtf/NeverDestroyed.h>
</ins><span class="cx"> #include <wtf/text/StringBuilder.h>
</span><ins>+#include <wtf/text/StringHash.h>
</ins><span class="cx">
</span><span class="cx"> namespace WebCore {
</span><span class="cx">
</span><span class="lines">@@ -35,6 +38,10 @@
</span><span class="cx"> template<typename CharacterType> static bool isC0Control(CharacterType character) { return character <= 0x0001F; }
</span><span class="cx"> template<typename CharacterType> static bool isC0ControlOrSpace(CharacterType character) { return isC0Control(character) || character == 0x0020; }
</span><span class="cx"> template<typename CharacterType> static bool isTabOrNewline(CharacterType character) { return character == 0x0009 || character == 0x000A || character == 0x000D; }
</span><ins>+template<typename CharacterType> static bool isInSimpleEncodeSet(CharacterType character) { return isC0Control(character) || character > 0x007E; }
+template<typename CharacterType> static bool isInDefaultEncodeSet(CharacterType character) { return isInSimpleEncodeSet(character) || character == 0x0020 || character == '"' || character == '#' || character == '<' || character == '>' || character == '?' || character == '`' || character == '{' || character == '}'; }
+template<typename CharacterType> static bool isInUserInfoEncodeSet(CharacterType character) { return isInDefaultEncodeSet(character) || character == '/' || character == ':' || character == ';' || character == '=' || character == '@' || character == '[' || character == '\\' || character == ']' || character == '^' || character == '|'; }
+template<typename CharacterType> static bool isInvalidDomainCharacter(CharacterType character) { return character == 0x0000 || character == 0x0009 || character == 0x000A || character == 0x000D || character == 0x0020 || character == '#' || character == '%' || character == '/' || character == ':' || character == '?' || character == '@' || character == '[' || character == '\\' || character == ']'; }
</ins><span class="cx">
</span><span class="cx"> static bool isWindowsDriveLetter(StringView::CodePoints::Iterator iterator, const StringView::CodePoints::Iterator& end)
</span><span class="cx"> {
</span><span class="lines">@@ -63,9 +70,74 @@
</span><span class="cx"> if (iterator == end)
</span><span class="cx"> return true;
</span><span class="cx"> ++iterator;
</span><del>- return *iterator != '/' && *iterator != '\\' && *iterator != '?' && *iterator == '#';
</del><ins>+ if (iterator == end)
+ return true;
+ return *iterator != '/' && *iterator != '\\' && *iterator != '?' && *iterator != '#';
</ins><span class="cx"> }
</span><span class="cx">
</span><ins>+static void percentEncode(uint8_t byte, StringBuilder& builder)
+{
+ builder.append('%');
+ builder.append(upperNibbleToASCIIHexDigit(byte));
+ builder.append(lowerNibbleToASCIIHexDigit(byte));
+}
+
+static void utf8PercentEncode(UChar32 codePoint, StringBuilder& builder, bool(*isInCodeSet)(UChar32))
+{
+ if (isInCodeSet(codePoint)) {
+ uint8_t buffer[U8_MAX_LENGTH];
+ int32_t offset = 0;
+ UBool error = false;
+ U8_APPEND(buffer, offset, U8_MAX_LENGTH, codePoint, error);
+ // FIXME: Check error.
+ for (int32_t i = 0; i < offset; ++i)
+ percentEncode(buffer[i], builder);
+ } else
+ builder.append(codePoint);
+}
+
+static bool shouldPercentEncodeQueryByte(uint8_t byte)
+{
+ if (byte < 0x21)
+ return true;
+ if (byte > 0x7E)
+ return true;
+ if (byte == 0x22)
+ return true;
+ if (byte == 0x23)
+ return true;
+ if (byte == 0x3C)
+ return true;
+ return byte == 0x3E;
+}
+
+static void encodeQuery(const StringBuilder& source, StringBuilder& destination, const TextEncoding& encoding)
+{
+ // FIXME: It is unclear in the spec what to do when encoding fails. The behavior should be specified and tested.
+ CString encoded = encoding.encode(StringView(source.toStringPreserveCapacity()), URLEncodedEntitiesForUnencodables);
+ const char* data = encoded.data();
+ size_t length = encoded.length();
+ for (size_t i = 0; i < length; ++i) {
+ uint8_t byte = data[i];
+ if (shouldPercentEncodeQueryByte(byte))
+ percentEncode(byte, destination);
+ else
+ destination.append(byte);
+ }
+}
+
+static bool isDefaultPort(const String& scheme, uint16_t port)
+{
+ static NeverDestroyed<HashMap<String, uint16_t>> defaultPorts(HashMap<String, uint16_t>({
+ {"ftp", 21},
+ {"gopher", 70},
+ {"http", 80},
+ {"https", 443},
+ {"ws", 80},
+ {"wss", 443}}));
+ return defaultPorts.get().get(scheme) == port;
+}
+
</ins><span class="cx"> static bool isSpecialScheme(const String& scheme)
</span><span class="cx"> {
</span><span class="cx"> return scheme == "ftp"
</span><span class="lines">@@ -159,6 +231,23 @@
</span><span class="cx">
</span><span class="cx"> static const char* dotASCIICode = "2e";
</span><span class="cx">
</span><ins>+static bool isPercentEncodedDot(StringView::CodePoints::Iterator c, const StringView::CodePoints::Iterator& end)
+{
+ if (c == end)
+ return false;
+ if (*c != '%')
+ return false;
+ ++c;
+ if (c == end)
+ return false;
+ if (*c != dotASCIICode[0])
+ return false;
+ ++c;
+ if (c == end)
+ return false;
+ return toASCIILower(*c) == dotASCIICode[1];
+}
+
</ins><span class="cx"> static bool isSingleDotPathSegment(StringView::CodePoints::Iterator c, const StringView::CodePoints::Iterator& end)
</span><span class="cx"> {
</span><span class="cx"> if (c == end)
</span><span class="lines">@@ -261,12 +350,15 @@
</span><span class="cx"> m_buffer.resize(m_url.m_pathAfterLastSlash);
</span><span class="cx"> }
</span><span class="cx">
</span><del>-URL URLParser::parse(const String& input, const URL& base, const TextEncoding&)
</del><ins>+URL URLParser::parse(const String& input, const URL& base, const TextEncoding& encoding)
</ins><span class="cx"> {
</span><span class="cx"> LOG(URLParser, "Parsing URL <%s> base <%s>", input.utf8().data(), base.string().utf8().data());
</span><span class="cx"> m_url = { };
</span><span class="cx"> m_buffer.clear();
</span><span class="cx"> m_buffer.reserveCapacity(input.length());
</span><ins>+
+ // FIXME: We shouldn't need to allocate another buffer for this.
+ StringBuilder queryBuffer;
</ins><span class="cx">
</span><span class="cx"> auto codePoints = StringView(input).codePoints();
</span><span class="cx"> auto c = codePoints.begin();
</span><span class="lines">@@ -347,6 +439,8 @@
</span><span class="cx"> break;
</span><span class="cx"> }
</span><span class="cx"> ++c;
</span><ins>+ while (c != end && isTabOrNewline(*c))
+ ++c;
</ins><span class="cx"> if (c == end) {
</span><span class="cx"> m_buffer.clear();
</span><span class="cx"> state = State::NoScheme;
</span><span class="lines">@@ -380,6 +474,7 @@
</span><span class="cx"> return { };
</span><span class="cx"> } else if (base.protocol() == "file") {
</span><span class="cx"> copyURLPartsUntil(base, URLPart::SchemeEnd);
</span><ins>+ m_buffer.append(':');
</ins><span class="cx"> state = State::File;
</span><span class="cx"> } else
</span><span class="cx"> state = State::Relative;
</span><span class="lines">@@ -479,12 +574,20 @@
</span><span class="cx"> if (*c == '@') {
</span><span class="cx"> parseAuthority(authorityOrHostBegin, c);
</span><span class="cx"> ++c;
</span><ins>+ while (c != end && isTabOrNewline(*c))
+ ++c;
</ins><span class="cx"> authorityOrHostBegin = c;
</span><span class="cx"> state = State::Host;
</span><ins>+ break;
</ins><span class="cx"> } else if (*c == '/' || *c == '?' || *c == '#') {
</span><span class="cx"> m_url.m_userEnd = m_buffer.length();
</span><span class="cx"> m_url.m_passwordEnd = m_url.m_userEnd;
</span><del>- parseHost(authorityOrHostBegin, c);
</del><ins>+ if (!parseHost(authorityOrHostBegin, c))
+ return { };
+ if (*c != '/') {
+ m_buffer.append('/');
+ m_url.m_pathAfterLastSlash = m_buffer.length();
+ }
</ins><span class="cx"> state = State::Path;
</span><span class="cx"> break;
</span><span class="cx"> }
</span><span class="lines">@@ -493,7 +596,8 @@
</span><span class="cx"> case State::Host:
</span><span class="cx"> LOG_STATE("Host");
</span><span class="cx"> if (*c == '/' || *c == '?' || *c == '#') {
</span><del>- parseHost(authorityOrHostBegin, c);
</del><ins>+ if (!parseHost(authorityOrHostBegin, c))
+ return { };
</ins><span class="cx"> state = State::Path;
</span><span class="cx"> break;
</span><span class="cx"> }
</span><span class="lines">@@ -509,7 +613,7 @@
</span><span class="cx"> ++c;
</span><span class="cx"> break;
</span><span class="cx"> case '?':
</span><del>- if (!base.isNull() && base.protocol() == "file")
</del><ins>+ if (!base.isNull() && base.protocolIs("file"))
</ins><span class="cx"> copyURLPartsUntil(base, URLPart::PathEnd);
</span><span class="cx"> m_buffer.append("///?");
</span><span class="cx"> m_url.m_userStart = m_buffer.length() - 2;
</span><span class="lines">@@ -523,7 +627,7 @@
</span><span class="cx"> ++c;
</span><span class="cx"> break;
</span><span class="cx"> case '#':
</span><del>- if (!base.isNull() && base.protocol() == "file")
</del><ins>+ if (!base.isNull() && base.protocolIs("file"))
</ins><span class="cx"> copyURLPartsUntil(base, URLPart::QueryEnd);
</span><span class="cx"> m_buffer.append("///#");
</span><span class="cx"> m_url.m_userStart = m_buffer.length() - 2;
</span><span class="lines">@@ -538,10 +642,9 @@
</span><span class="cx"> ++c;
</span><span class="cx"> break;
</span><span class="cx"> default:
</span><del>- if (shouldCopyFileURL(c, end)) {
- copyURLPartsUntil(base, URLPart::PathEnd);
- popPath();
- } else {
</del><ins>+ if (!base.isNull() && base.protocolIs("file") && shouldCopyFileURL(c, end))
+ copyURLPartsUntil(base, URLPart::PathAfterLastSlash);
+ else {
</ins><span class="cx"> m_buffer.append("///");
</span><span class="cx"> m_url.m_userStart = m_buffer.length() - 1;
</span><span class="cx"> m_url.m_userEnd = m_url.m_userStart;
</span><span class="lines">@@ -667,8 +770,17 @@
</span><span class="cx"> state = State::Fragment;
</span><span class="cx"> break;
</span><span class="cx"> }
</span><del>- // FIXME: Percent encode c
- m_buffer.append(*c);
</del><ins>+ if (isPercentEncodedDot(c, end)) {
+ m_buffer.append('.');
+ ASSERT(*c == '%');
+ ++c;
+ ASSERT(*c == dotASCIICode[0]);
+ ++c;
+ ASSERT(toASCIILower(*c) == dotASCIICode[1]);
+ ++c;
+ break;
+ }
+ utf8PercentEncode(*c, m_buffer, isInDefaultEncodeSet);
</ins><span class="cx"> ++c;
</span><span class="cx"> break;
</span><span class="cx"> case State::CannotBeABaseURLPath:
</span><span class="lines">@@ -688,11 +800,12 @@
</span><span class="cx"> case State::Query:
</span><span class="cx"> LOG_STATE("Query");
</span><span class="cx"> if (*c == '#') {
</span><ins>+ encodeQuery(queryBuffer, m_buffer, encoding);
</ins><span class="cx"> m_url.m_queryEnd = m_buffer.length();
</span><span class="cx"> state = State::Fragment;
</span><span class="cx"> break;
</span><span class="cx"> }
</span><del>- m_buffer.append(*c);
</del><ins>+ queryBuffer.append(*c);
</ins><span class="cx"> ++c;
</span><span class="cx"> break;
</span><span class="cx"> case State::Fragment:
</span><span class="lines">@@ -743,7 +856,8 @@
</span><span class="cx"> case State::Host:
</span><span class="cx"> if (state == State::Host)
</span><span class="cx"> LOG_FINAL_STATE("Host");
</span><del>- parseHost(authorityOrHostBegin, end);
</del><ins>+ if (!parseHost(authorityOrHostBegin, end))
+ return { };
</ins><span class="cx"> m_buffer.append('/');
</span><span class="cx"> m_url.m_pathEnd = m_url.m_portEnd + 1;
</span><span class="cx"> m_url.m_pathAfterLastSlash = m_url.m_pathEnd;
</span><span class="lines">@@ -832,6 +946,7 @@
</span><span class="cx"> break;
</span><span class="cx"> case State::Query:
</span><span class="cx"> LOG_FINAL_STATE("Query");
</span><ins>+ encodeQuery(queryBuffer, m_buffer, encoding);
</ins><span class="cx"> m_url.m_queryEnd = m_buffer.length();
</span><span class="cx"> m_url.m_fragmentEnd = m_url.m_queryEnd;
</span><span class="cx"> break;
</span><span class="lines">@@ -1131,6 +1246,73 @@
</span><span class="cx"> return address;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+static String percentDecode(const String& input)
+{
+ StringBuilder output;
+ RELEASE_ASSERT(input.is8Bit());
+ const LChar* inputBytes = input.characters8();
+ size_t length = input.length();
+
+ for (size_t i = 0; i < length; ++i) {
+ uint8_t byte = inputBytes[i];
+ if (byte != '%')
+ output.append(byte);
+ else if (i < length - 2) {
+ if (isASCIIHexDigit(inputBytes[i + 1]) && isASCIIHexDigit(inputBytes[i + 2])) {
+ output.append(toASCIIHexValue(inputBytes[i + 1], inputBytes[i + 2]));
+ i += 2;
+ } else
+ output.append(byte);
+ } else
+ output.append(byte);
+ }
+ return output.toStringPreserveCapacity();
+}
+
+static Optional<String> domainToASCII(const String& domain)
+{
+ // FIXME: Implement correctly
+ CString utf8 = domain.utf8();
+ return String(utf8.data(), utf8.length());
+}
+
+static bool hasInvalidDomainCharacter(const String& asciiDomain)
+{
+ RELEASE_ASSERT(asciiDomain.is8Bit());
+ const LChar* characters = asciiDomain.characters8();
+ for (size_t i = 0; i < asciiDomain.length(); ++i) {
+ if (isInvalidDomainCharacter(characters[i]))
+ return true;
+ }
+ return false;
+}
+
+bool URLParser::parsePort(StringView::CodePoints::Iterator& iterator, const StringView::CodePoints::Iterator& end)
+{
+ uint32_t port = 0;
+ ASSERT(iterator != end);
+ for (; iterator != end; ++iterator) {
+ if (isTabOrNewline(*iterator))
+ continue;
+ if (isASCIIDigit(*iterator)) {
+ port = port * 10 + *iterator - '0';
+ if (port > std::numeric_limits<uint16_t>::max())
+ return false;
+ } else
+ return false;
+ }
+
+ // FIXME: This shouldn't need a String allocation.
+ String scheme = m_buffer.toStringPreserveCapacity().substring(0, m_url.m_schemeEnd);
+ if (isDefaultPort(scheme, port)) {
+ ASSERT(m_buffer[m_buffer.length() - 1] == ':');
+ m_buffer.resize(m_buffer.length() - 1);
+ } else
+ m_buffer.appendNumber(port);
+
+ return true;
+}
+
</ins><span class="cx"> bool URLParser::parseHost(StringView::CodePoints::Iterator& iterator, const StringView::CodePoints::Iterator& end)
</span><span class="cx"> {
</span><span class="cx"> if (iterator == end)
</span><span class="lines">@@ -1148,7 +1330,30 @@
</span><span class="cx"> return true;
</span><span class="cx"> }
</span><span class="cx"> }
</span><del>- if (auto address = parseIPv4Host(iterator, end)) {
</del><ins>+
+ // FIXME: We probably don't need to make so many buffers and String copies.
+ StringBuilder utf8Encoded;
+ for (; iterator != end; ++iterator) {
+ if (isTabOrNewline(*iterator))
+ continue;
+ if (*iterator == ':')
+ break;
+ uint8_t buffer[U8_MAX_LENGTH];
+ int32_t offset = 0;
+ UBool error = false;
+ U8_APPEND(buffer, offset, U8_MAX_LENGTH, *iterator, error);
+ // FIXME: Check error.
+ utf8Encoded.append(buffer, offset);
+ }
+ String percentDecoded = percentDecode(utf8Encoded.toStringPreserveCapacity());
+ RELEASE_ASSERT(percentDecoded.is8Bit());
+ String domain = String::fromUTF8(percentDecoded.characters8(), percentDecoded.length());
+ auto asciiDomain = domainToASCII(domain);
+ if (!asciiDomain || hasInvalidDomainCharacter(asciiDomain.value()))
+ return false;
+
+ auto asciiDomainCodePoints = StringView(asciiDomain.value()).codePoints();
+ if (auto address = parseIPv4Host(asciiDomainCodePoints.begin(), asciiDomainCodePoints.end())) {
</ins><span class="cx"> serializeIPv4(address.value(), m_buffer);
</span><span class="cx"> m_url.m_hostEnd = m_buffer.length();
</span><span class="cx"> // FIXME: Handle the port correctly.
</span><span class="lines">@@ -1155,20 +1360,21 @@
</span><span class="cx"> m_url.m_portEnd = m_buffer.length();
</span><span class="cx"> return true;
</span><span class="cx"> }
</span><del>- for (; iterator != end; ++iterator) {
- if (*iterator == ':') {
</del><ins>+
+ m_buffer.append(asciiDomain.value());
+ m_url.m_hostEnd = m_buffer.length();
+ if (iterator != end) {
+ ASSERT(*iterator == ':');
+ ++iterator;
+ while (iterator != end && isTabOrNewline(*iterator))
</ins><span class="cx"> ++iterator;
</span><del>- m_url.m_hostEnd = m_buffer.length();
</del><ins>+ if (iterator != end) {
</ins><span class="cx"> m_buffer.append(':');
</span><del>- for (; iterator != end; ++iterator)
- m_buffer.append(*iterator);
- m_url.m_portEnd = m_buffer.length();
- return true;
</del><ins>+ if (!parsePort(iterator, end))
+ return false;
</ins><span class="cx"> }
</span><del>- m_buffer.append(*iterator);
</del><span class="cx"> }
</span><del>- m_url.m_hostEnd = m_buffer.length();
- m_url.m_portEnd = m_url.m_hostEnd;
</del><ins>+ m_url.m_portEnd = m_buffer.length();
</ins><span class="cx"> return true;
</span><span class="cx"> }
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformURLParserh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/URLParser.h (205492 => 205493)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/URLParser.h        2016-09-06 18:02:28 UTC (rev 205492)
+++ trunk/Source/WebCore/platform/URLParser.h        2016-09-06 18:16:07 UTC (rev 205493)
</span><span class="lines">@@ -44,6 +44,7 @@
</span><span class="cx"> StringBuilder m_buffer;
</span><span class="cx"> void parseAuthority(StringView::CodePoints::Iterator&, const StringView::CodePoints::Iterator& end);
</span><span class="cx"> bool parseHost(StringView::CodePoints::Iterator&, const StringView::CodePoints::Iterator& end);
</span><ins>+ bool parsePort(StringView::CodePoints::Iterator&, const StringView::CodePoints::Iterator& end);
</ins><span class="cx">
</span><span class="cx"> enum class URLPart;
</span><span class="cx"> void copyURLPartsUntil(const URL& base, URLPart);
</span></span></pre></div>
<a id="trunkToolsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Tools/ChangeLog (205492 => 205493)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/ChangeLog        2016-09-06 18:02:28 UTC (rev 205492)
+++ trunk/Tools/ChangeLog        2016-09-06 18:16:07 UTC (rev 205493)
</span><span class="lines">@@ -1,3 +1,13 @@
</span><ins>+2016-09-05 Alex Christensen <achristensen@webkit.org>
+
+ Implement relative file urls and begin implementing character encoding in URLParser
+ https://bugs.webkit.org/show_bug.cgi?id=161618
+
+ Reviewed by Tim Horton.
+
+ * TestWebKitAPI/Tests/WebCore/URLParser.cpp:
+ (TestWebKitAPI::TEST_F):
+
</ins><span class="cx"> 2016-09-06 Commit Queue <commit-queue@webkit.org>
</span><span class="cx">
</span><span class="cx"> Unreviewed, rolling out r205480.
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPITestsWebCoreURLParsercpp"></a>
<div class="modfile"><h4>Modified: trunk/Tools/TestWebKitAPI/Tests/WebCore/URLParser.cpp (205492 => 205493)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/Tests/WebCore/URLParser.cpp        2016-09-06 18:02:28 UTC (rev 205492)
+++ trunk/Tools/TestWebKitAPI/Tests/WebCore/URLParser.cpp        2016-09-06 18:16:07 UTC (rev 205493)
</span><span class="lines">@@ -165,6 +165,9 @@
</span><span class="cx"> checkURL("file:///#fragment", {"file", "", "", "", 0, "/", "", "fragment", "file:///#fragment"});
</span><span class="cx"> checkURL("file:////?query", {"file", "", "", "", 0, "//", "query", "", "file:////?query"});
</span><span class="cx"> checkURL("file:////#fragment", {"file", "", "", "", 0, "//", "", "fragment", "file:////#fragment"});
</span><ins>+ checkURL("http://host/A b", {"http", "", "", "host", 0, "/A%20b", "", "", "http://host/A%20b"});
+ checkURL("http://host/a%20B", {"http", "", "", "host", 0, "/a%20B", "", "", "http://host/a%20B"});
+ checkURL("http://host?q=@ <>!#fragment", {"http", "", "", "host", 0, "/", "q=@%20%3C%3E!", "fragment", "http://host/?q=@%20%3C%3E!#fragment"});
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> static void checkRelativeURL(const String& urlString, const String& baseURLString, const ExpectedParts& parts)
</span><span class="lines">@@ -204,6 +207,8 @@
</span><span class="cx"> checkRelativeURL("http://whatwg.org/index.html", "http://webkit.org/path1/path2/", {"http", "", "", "whatwg.org", 0, "/index.html", "", "", "http://whatwg.org/index.html"});
</span><span class="cx"> checkRelativeURL("index.html", "http://webkit.org/path1/path2/page.html?query#fragment", {"http", "", "", "webkit.org", 0, "/path1/path2/index.html", "", "", "http://webkit.org/path1/path2/index.html"});
</span><span class="cx"> checkRelativeURL("//whatwg.org/index.html", "https://www.webkit.org/path", {"https", "", "", "whatwg.org", 0, "/index.html", "", "", "https://whatwg.org/index.html"});
</span><ins>+ checkRelativeURL("http://example\t.\norg", "http://example.org/foo/bar", {"http", "", "", "example.org", 0, "/", "", "", "http://example.org/"});
+ checkRelativeURL("test", "file:///path1/path2", {"file", "", "", "", 0, "/path1/test", "", "", "file:///path1/test"});
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> static void checkURLDifferences(const String& urlString, const ExpectedParts& partsNew, const ExpectedParts& partsOld)
</span><span class="lines">@@ -338,8 +343,74 @@
</span><span class="cx"> checkURLDifferences("file:path",
</span><span class="cx"> {"file", "", "", "", 0, "/path", "", "", "file:///path"},
</span><span class="cx"> {"file", "", "", "", 0, "path", "", "", "file://path"});
</span><ins>+
+ // FIXME: Fix and test incomplete percent encoded characters in the middle and end of the input string.
+ // FIXME: Fix and test percent encoded upper case characters in the host.
+ checkURLDifferences("http://host%73",
+ {"http", "", "", "hosts", 0, "/", "", "", "http://hosts/"},
+ {"http", "", "", "host%73", 0, "/", "", "", "http://host%73/"});
+
+ // URLParser matches Chrome and the spec, but not URL::parse or Firefox.
+ checkURLDifferences("http://host/path%2e.%2E",
+ {"http", "", "", "host", 0, "/path...", "", "", "http://host/path..."},
+ {"http", "", "", "host", 0, "/path%2e.%2E", "", "", "http://host/path%2e.%2E"});
</ins><span class="cx"> }
</span><span class="cx">
</span><ins>+TEST_F(URLParserTest, DefaultPort)
+{
+ checkURL("ftp://host:21/", {"ftp", "", "", "host", 0, "/", "", "", "ftp://host/"});
+ checkURL("ftp://host:22/", {"ftp", "", "", "host", 22, "/", "", "", "ftp://host:22/"});
+ checkURLDifferences("ftp://host:21",
+ {"ftp", "", "", "host", 0, "/", "", "", "ftp://host/"},
+ {"ftp", "", "", "host", 0, "", "", "", "ftp://host"});
+ checkURLDifferences("ftp://host:22",
+ {"ftp", "", "", "host", 22, "/", "", "", "ftp://host:22/"},
+ {"ftp", "", "", "host", 22, "", "", "", "ftp://host:22"});
+
+ checkURL("gopher://host:70/", {"gopher", "", "", "host", 0, "/", "", "", "gopher://host/"});
+ checkURL("gopher://host:71/", {"gopher", "", "", "host", 71, "/", "", "", "gopher://host:71/"});
+ // Spec, Chrome, Firefox, and URLParser have "/", URL::parse does not.
+ // Spec, Chrome, URLParser, URL::parse recognize gopher default port, Firefox does not.
+ checkURLDifferences("gopher://host:70",
+ {"gopher", "", "", "host", 0, "/", "", "", "gopher://host/"},
+ {"gopher", "", "", "host", 0, "", "", "", "gopher://host"});
+ checkURLDifferences("gopher://host:71",
+ {"gopher", "", "", "host", 71, "/", "", "", "gopher://host:71/"},
+ {"gopher", "", "", "host", 71, "", "", "", "gopher://host:71"});
+
+ checkURL("http://host:80", {"http", "", "", "host", 0, "/", "", "", "http://host/"});
+ checkURL("http://host:80/", {"http", "", "", "host", 0, "/", "", "", "http://host/"});
+ checkURL("http://host:81", {"http", "", "", "host", 81, "/", "", "", "http://host:81/"});
+ checkURL("http://host:81/", {"http", "", "", "host", 81, "/", "", "", "http://host:81/"});
+
+ checkURL("https://host:443", {"https", "", "", "host", 0, "/", "", "", "https://host/"});
+ checkURL("https://host:443/", {"https", "", "", "host", 0, "/", "", "", "https://host/"});
+ checkURL("https://host:444", {"https", "", "", "host", 444, "/", "", "", "https://host:444/"});
+ checkURL("https://host:444/", {"https", "", "", "host", 444, "/", "", "", "https://host:444/"});
+
+ checkURL("ws://host:80/", {"ws", "", "", "host", 0, "/", "", "", "ws://host/"});
+ checkURL("ws://host:81/", {"ws", "", "", "host", 81, "/", "", "", "ws://host:81/"});
+ // URLParser matches Chrome and Firefox, but not URL::parse
+ checkURLDifferences("ws://host:80",
+ {"ws", "", "", "host", 0, "/", "", "", "ws://host/"},
+ {"ws", "", "", "host", 0, "", "", "", "ws://host"});
+ checkURLDifferences("ws://host:81",
+ {"ws", "", "", "host", 81, "/", "", "", "ws://host:81/"},
+ {"ws", "", "", "host", 81, "", "", "", "ws://host:81"});
+
+ checkURL("wss://host:443/", {"wss", "", "", "host", 0, "/", "", "", "wss://host/"});
+ checkURL("wss://host:444/", {"wss", "", "", "host", 444, "/", "", "", "wss://host:444/"});
+ // URLParser matches Chrome and Firefox, but not URL::parse
+ checkURLDifferences("wss://host:443",
+ {"wss", "", "", "host", 0, "/", "", "", "wss://host/"},
+ {"wss", "", "", "host", 0, "", "", "", "wss://host"});
+ checkURLDifferences("wss://host:444",
+ {"wss", "", "", "host", 444, "/", "", "", "wss://host:444/"},
+ {"wss", "", "", "host", 444, "", "", "", "wss://host:444"});
+
+ // FIXME: Fix and check unknown schemes with ports, as well as ftps.
+}
+
</ins><span class="cx"> static void shouldFail(const String& urlString)
</span><span class="cx"> {
</span><span class="cx"> URLParser parser;
</span></span></pre>
</div>
</div>
</body>
</html>