Title: [206329] trunk
Revision
206329
Author
achristen...@apple.com
Date
2016-09-23 13:58:03 -0700 (Fri, 23 Sep 2016)

Log Message

Refactor URLParser
https://bugs.webkit.org/show_bug.cgi?id=162511

Reviewed by Brady Eidson.

Source/WebCore:

Make the constructor take the parameters instead of URL::parse.
Now we don't need to copy the input string on failure.
Also, turn some static functions into methods so they will be able to access member variables.

Covered by existing and new API tests.

* platform/URL.cpp:
(WebCore::URL::URL):
(WebCore::URL::setProtocol):
(WebCore::URL::setHost):
(WebCore::URL::removePort):
(WebCore::URL::setPort):
(WebCore::URL::setHostAndPort):
(WebCore::URL::setUser):
(WebCore::URL::setPass):
(WebCore::URL::setFragmentIdentifier):
(WebCore::URL::removeFragmentIdentifier):
(WebCore::URL::setQuery):
(WebCore::URL::setPath):
* platform/URLParser.cpp:
(WebCore::URLParser::incrementIteratorSkippingTabAndNewLine):
(WebCore::URLParser::isWindowsDriveLetter):
(WebCore::URLParser::checkWindowsDriveLetter):
(WebCore::URLParser::shouldCopyFileURL):
(WebCore::URLParser::failure):
(WebCore::URLParser::URLParser):
(WebCore::URLParser::parse):
(WebCore::incrementIteratorSkippingTabAndNewLine): Deleted.
(WebCore::isWindowsDriveLetter): Deleted.
(WebCore::checkWindowsDriveLetter): Deleted.
(WebCore::shouldCopyFileURL): Deleted.
* platform/URLParser.h:
(WebCore::URLParser::URLParser):
(WebCore::URLParser::result):
(WebCore::URLParser::parse): Deleted.
* platform/cf/URLCF.cpp:
(WebCore::URL::URL):
Drive-by fix: Actually assign the URL to be the result of parsing.
* platform/mac/URLMac.mm:
(WebCore::URL::URL):

Tools:

* TestWebKitAPI/Tests/WebCore/URLParser.cpp:
(TestWebKitAPI::TEST_F):
(TestWebKitAPI::checkURL):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (206328 => 206329)


--- trunk/Source/WebCore/ChangeLog	2016-09-23 20:33:53 UTC (rev 206328)
+++ trunk/Source/WebCore/ChangeLog	2016-09-23 20:58:03 UTC (rev 206329)
@@ -1,5 +1,53 @@
 2016-09-23  Alex Christensen  <achristen...@webkit.org>
 
+        Refactor URLParser
+        https://bugs.webkit.org/show_bug.cgi?id=162511
+
+        Reviewed by Brady Eidson.
+
+        Make the constructor take the parameters instead of URL::parse.
+        Now we don't need to copy the input string on failure.
+        Also, turn some static functions into methods so they will be able to access member variables.
+
+        Covered by existing and new API tests.
+
+        * platform/URL.cpp:
+        (WebCore::URL::URL):
+        (WebCore::URL::setProtocol):
+        (WebCore::URL::setHost):
+        (WebCore::URL::removePort):
+        (WebCore::URL::setPort):
+        (WebCore::URL::setHostAndPort):
+        (WebCore::URL::setUser):
+        (WebCore::URL::setPass):
+        (WebCore::URL::setFragmentIdentifier):
+        (WebCore::URL::removeFragmentIdentifier):
+        (WebCore::URL::setQuery):
+        (WebCore::URL::setPath):
+        * platform/URLParser.cpp:
+        (WebCore::URLParser::incrementIteratorSkippingTabAndNewLine):
+        (WebCore::URLParser::isWindowsDriveLetter):
+        (WebCore::URLParser::checkWindowsDriveLetter):
+        (WebCore::URLParser::shouldCopyFileURL):
+        (WebCore::URLParser::failure):
+        (WebCore::URLParser::URLParser):
+        (WebCore::URLParser::parse):
+        (WebCore::incrementIteratorSkippingTabAndNewLine): Deleted.
+        (WebCore::isWindowsDriveLetter): Deleted.
+        (WebCore::checkWindowsDriveLetter): Deleted.
+        (WebCore::shouldCopyFileURL): Deleted.
+        * platform/URLParser.h:
+        (WebCore::URLParser::URLParser):
+        (WebCore::URLParser::result):
+        (WebCore::URLParser::parse): Deleted.
+        * platform/cf/URLCF.cpp:
+        (WebCore::URL::URL):
+        Drive-by fix: Actually assign the URL to be the result of parsing.
+        * platform/mac/URLMac.mm:
+        (WebCore::URL::URL):
+
+2016-09-23  Alex Christensen  <achristen...@webkit.org>
+
         Remove URLParser serialized template
         https://bugs.webkit.org/show_bug.cgi?id=162501
 

Modified: trunk/Source/WebCore/platform/URL.cpp (206328 => 206329)


--- trunk/Source/WebCore/platform/URL.cpp	2016-09-23 20:33:53 UTC (rev 206328)
+++ trunk/Source/WebCore/platform/URL.cpp	2016-09-23 20:58:03 UTC (rev 206329)
@@ -441,8 +441,8 @@
 URL::URL(ParsedURLStringTag, const String& url)
 {
     if (URLParser::enabled()) {
-        URLParser parser;
-        *this = parser.parse(url);
+        URLParser parser(url);
+        *this = parser.result();
     } else
         parse(url);
 #if OS(WINDOWS)
@@ -456,8 +456,8 @@
 URL::URL(const URL& base, const String& relative)
 {
     if (URLParser::enabled()) {
-        URLParser parser;
-        *this = parser.parse(relative, base);
+        URLParser parser(relative, base);
+        *this = parser.result();
     } else
         init(base, relative, UTF8Encoding());
 }
@@ -465,8 +465,8 @@
 URL::URL(const URL& base, const String& relative, const TextEncoding& encoding)
 {
     if (URLParser::enabled()) {
-        URLParser parser;
-        *this = parser.parse(relative, base, encoding);
+        URLParser parser(relative, base, encoding);
+        *this = parser.result();
     } else {
         // For UTF-{7,16,32}, we want to use UTF-8 for the query part as
         // we do when submitting a form. A form with GET method
@@ -865,8 +865,8 @@
 
     if (!m_isValid) {
         if (URLParser::enabled()) {
-            URLParser parser;
-            *this = parser.parse(makeString(newProtocol, ":", m_string));
+            URLParser parser(makeString(newProtocol, ":", m_string));
+            *this = parser.result();
         } else
             parse(newProtocol + ':' + m_string);
         return true;
@@ -873,8 +873,8 @@
     }
 
     if (URLParser::enabled()) {
-        URLParser parser;
-        *this = parser.parse(makeString(newProtocol, m_string.substring(m_schemeEnd)));
+        URLParser parser(makeString(newProtocol, m_string.substring(m_schemeEnd)));
+        *this = parser.result();
     } else
         parse(newProtocol + m_string.substring(m_schemeEnd));
 
@@ -945,8 +945,8 @@
     builder.append(m_string.substring(m_hostEnd));
     
     if (URLParser::enabled()) {
-        URLParser parser;
-        *this = parser.parse(builder.toString());
+        URLParser parser(builder.toString());
+        *this = parser.result();
     } else
         parse(builder.toString());
 }
@@ -956,8 +956,8 @@
     if (m_hostEnd == m_portEnd)
         return;
     if (URLParser::enabled()) {
-        URLParser parser;
-        *this = parser.parse(m_string.left(m_hostEnd) + m_string.substring(m_portEnd));
+        URLParser parser(m_string.left(m_hostEnd) + m_string.substring(m_portEnd));
+        *this = parser.result();
     } else
         parse(m_string.left(m_hostEnd) + m_string.substring(m_portEnd));
 }
@@ -971,8 +971,8 @@
     unsigned portStart = (colonNeeded ? m_hostEnd : m_hostEnd + 1);
 
     if (URLParser::enabled()) {
-        URLParser parser;
-        *this = parser.parse(makeString(m_string.left(portStart), (colonNeeded ? ":" : ""), String::number(i), m_string.substring(m_portEnd)));
+        URLParser parser(makeString(m_string.left(portStart), (colonNeeded ? ":" : ""), String::number(i), m_string.substring(m_portEnd)));
+        *this = parser.result();
     } else
         parse(m_string.left(portStart) + (colonNeeded ? ":" : "") + String::number(i) + m_string.substring(m_portEnd));
 }
@@ -1016,8 +1016,8 @@
     builder.append(m_string.substring(m_portEnd));
 
     if (URLParser::enabled()) {
-        URLParser parser;
-        *this = parser.parse(builder.toString());
+        URLParser parser(builder.toString());
+        *this = parser.result();
     } else
         parse(builder.toString());
 }
@@ -1039,8 +1039,8 @@
         if (end == m_hostEnd || (end == m_passwordEnd && m_string[end] != '@'))
             u.append('@');
         if (URLParser::enabled()) {
-            URLParser parser;
-            *this = parser.parse(makeString(m_string.left(m_userStart), u, m_string.substring(end)));
+            URLParser parser(makeString(m_string.left(m_userStart), u, m_string.substring(end)));
+            *this = parser.result();
         } else
             parse(m_string.left(m_userStart) + u + m_string.substring(end));
     } else {
@@ -1050,8 +1050,8 @@
         // We don't want to parse in the extremely common case where we are not going to make a change.
         if (m_userStart != end) {
             if (URLParser::enabled()) {
-                URLParser parser;
-                *this = parser.parse(makeString(m_string.left(m_userStart), m_string.substring(end)));
+                URLParser parser(makeString(m_string.left(m_userStart), m_string.substring(end)));
+                *this = parser.result();
             } else
                 parse(m_string.left(m_userStart) + m_string.substring(end));
         }
@@ -1072,8 +1072,8 @@
         if (end != m_hostEnd && m_string[end] == '@')
             end += 1;
         if (URLParser::enabled()) {
-            URLParser parser;
-            *this = parser.parse(makeString(m_string.left(m_userEnd), p, m_string.substring(end)));
+            URLParser parser(makeString(m_string.left(m_userEnd), p, m_string.substring(end)));
+            *this = parser.result();
         } else
             parse(m_string.left(m_userEnd) + p + m_string.substring(end));
     } else {
@@ -1083,8 +1083,8 @@
         // We don't want to parse in the extremely common case where we are not going to make a change.
         if (m_userEnd != end) {
             if (URLParser::enabled()) {
-                URLParser parser;
-                *this = parser.parse(makeString(m_string.left(m_userEnd), m_string.substring(end)));
+                URLParser parser(makeString(m_string.left(m_userEnd), m_string.substring(end)));
+                *this = parser.result();
             } else
                 parse(m_string.left(m_userEnd) + m_string.substring(end));
         }
@@ -1098,8 +1098,8 @@
 
     // FIXME: Non-ASCII characters must be encoded and escaped to match parse() expectations.
     if (URLParser::enabled()) {
-        URLParser parser;
-        *this = parser.parse(makeString(m_string.left(m_queryEnd), "#", s));
+        URLParser parser(makeString(m_string.left(m_queryEnd), "#", s));
+        *this = parser.result();
     } else
         parse(m_string.left(m_queryEnd) + "#" + s);
 }
@@ -1110,8 +1110,8 @@
         return;
     if (URLParser::enabled()) {
         // FIXME: We shouldn't need to parse here.
-        URLParser parser;
-        *this = parser.parse(m_string.left(m_queryEnd));
+        URLParser parser(m_string.left(m_queryEnd));
+        *this = parser.result();
     } else
         parse(m_string.left(m_queryEnd));
 }
@@ -1127,14 +1127,14 @@
     // https://webkit.org/b/161176
     if ((query.isEmpty() || query[0] != '?') && !query.isNull()) {
         if (URLParser::enabled()) {
-            URLParser parser;
-            *this = parser.parse(makeString(m_string.left(m_pathEnd), "?", query, m_string.substring(m_queryEnd)));
+            URLParser parser(makeString(m_string.left(m_pathEnd), "?", query, m_string.substring(m_queryEnd)));
+            *this = parser.result();
         } else
             parse(m_string.left(m_pathEnd) + "?" + query + m_string.substring(m_queryEnd));
     } else {
         if (URLParser::enabled()) {
-            URLParser parser;
-            *this = parser.parse(makeString(m_string.left(m_pathEnd), query, m_string.substring(m_queryEnd)));
+            URLParser parser(makeString(m_string.left(m_pathEnd), query, m_string.substring(m_queryEnd)));
+            *this = parser.result();
         } else
             parse(m_string.left(m_pathEnd) + query + m_string.substring(m_queryEnd));
     }
@@ -1153,8 +1153,8 @@
         path = "/" + path;
 
     if (URLParser::enabled()) {
-        URLParser parser;
-        *this = parser.parse(makeString(m_string.left(m_portEnd), encodeWithURLEscapeSequences(path), m_string.substring(m_pathEnd)));
+        URLParser parser(makeString(m_string.left(m_portEnd), encodeWithURLEscapeSequences(path), m_string.substring(m_pathEnd)));
+        *this = parser.result();
     } else
         parse(m_string.left(m_portEnd) + encodeWithURLEscapeSequences(path) + m_string.substring(m_pathEnd));
 }

Modified: trunk/Source/WebCore/platform/URLParser.cpp (206328 => 206329)


--- trunk/Source/WebCore/platform/URLParser.cpp	2016-09-23 20:33:53 UTC (rev 206328)
+++ trunk/Source/WebCore/platform/URLParser.cpp	2016-09-23 20:58:03 UTC (rev 206329)
@@ -404,7 +404,7 @@
 static bool shouldPercentEncodeQueryByte(uint8_t byte) { return characterClassTable[byte] & QueryPercent; }
 
 template<typename CharacterType>
-void incrementIteratorSkippingTabAndNewLine(CodePointIterator<CharacterType>& iterator)
+void URLParser::incrementIteratorSkippingTabAndNewLine(CodePointIterator<CharacterType>& iterator)
 {
     ++iterator;
     while (!iterator.atEnd() && isTabOrNewline(*iterator))
@@ -412,7 +412,7 @@
 }
 
 template<typename CharacterType>
-inline static bool isWindowsDriveLetter(CodePointIterator<CharacterType> iterator)
+bool URLParser::isWindowsDriveLetter(CodePointIterator<CharacterType> iterator)
 {
     if (iterator.atEnd() || !isASCIIAlpha(*iterator))
         return false;
@@ -430,7 +430,7 @@
 }
 
 template<typename CharacterType>
-inline static void checkWindowsDriveLetter(CodePointIterator<CharacterType>& iterator, Vector<LChar>& asciiBuffer)
+void URLParser::checkWindowsDriveLetter(CodePointIterator<CharacterType>& iterator, Vector<LChar>& asciiBuffer)
 {
     if (isWindowsDriveLetter(iterator)) {
         asciiBuffer.reserveCapacity(asciiBuffer.size() + 2);
@@ -444,7 +444,7 @@
 }
 
 template<typename CharacterType>
-inline static bool shouldCopyFileURL(CodePointIterator<CharacterType> iterator)
+bool URLParser::shouldCopyFileURL(CodePointIterator<CharacterType> iterator)
 {
     if (!isWindowsDriveLetter(iterator))
         return true;
@@ -896,36 +896,25 @@
     m_asciiBuffer.resize(m_url.m_pathAfterLastSlash);
 }
 
-template<typename CharacterType>
-URL URLParser::failure(const CharacterType* input, unsigned length)
+void URLParser::failure()
 {
-    URL url;
-    url.m_isValid = false;
-    url.m_protocolIsInHTTPFamily = false;
-    url.m_cannotBeABaseURL = false;
-    url.m_schemeEnd = 0;
-    url.m_userStart = 0;
-    url.m_userEnd = 0;
-    url.m_passwordEnd = 0;
-    url.m_hostEnd = 0;
-    url.m_portEnd = 0;
-    url.m_pathAfterLastSlash = 0;
-    url.m_pathEnd = 0;
-    url.m_queryEnd = 0;
-    url.m_fragmentEnd = 0;
-    url.m_string = String(input, length);
-    return url;
+    m_url.invalidate();
+    m_url.m_string = m_inputString;
 }
 
-URL URLParser::parse(const String& input, const URL& base, const TextEncoding& encoding)
+URLParser::URLParser(const String& input, const URL& base, const TextEncoding& encoding)
+    : m_inputString(input)
 {
+    if (input.isNull())
+        return;
     if (input.is8Bit())
-        return parse(input.characters8(), input.length(), base, encoding);
-    return parse(input.characters16(), input.length(), base, encoding);
+        parse(input.characters8(), input.length(), base, encoding);
+    else
+        parse(input.characters16(), input.length(), base, encoding);
 }
 
 template<typename CharacterType>
-URL URLParser::parse(const CharacterType* input, const unsigned length, const URL& base, const TextEncoding& encoding)
+void URLParser::parse(const CharacterType* input, const unsigned length, const URL& base, const TextEncoding& encoding)
 {
     LOG(URLParser, "Parsing URL <%s> base <%s>", String(input, length).utf8().data(), base.string().utf8().data());
     m_url = { };
@@ -1051,8 +1040,10 @@
             break;
         case State::NoScheme:
             LOG_STATE("NoScheme");
-            if (!base.isValid() || (base.m_cannotBeABaseURL && *c != '#'))
-                return failure(input, length);
+            if (!base.isValid() || (base.m_cannotBeABaseURL && *c != '#')) {
+                failure();
+                return;
+            }
             if (base.m_cannotBeABaseURL && *c == '#') {
                 copyURLPartsUntil(base, URLPart::QueryEnd);
                 state = State::Fragment;
@@ -1073,8 +1064,10 @@
             if (*c == '/') {
                 m_asciiBuffer.append('/');
                 incrementIteratorSkippingTabAndNewLine(c);
-                if (c.atEnd())
-                    return failure(input, length);
+                if (c.atEnd()) {
+                    failure();
+                    return;
+                }
                 if (*c == '/') {
                     m_asciiBuffer.append('/');
                     state = State::SpecialAuthorityIgnoreSlashes;
@@ -1186,8 +1179,10 @@
                 if (isSlash || *c == '?' || *c == '#') {
                     m_url.m_userEnd = m_asciiBuffer.size();
                     m_url.m_passwordEnd = m_url.m_userEnd;
-                    if (!parseHostAndPort(CodePointIterator<CharacterType>(authorityOrHostBegin, c)))
-                        return failure(input, length);
+                    if (!parseHostAndPort(CodePointIterator<CharacterType>(authorityOrHostBegin, c))) {
+                        failure();
+                        return;
+                    }
                     if (!isSlash) {
                         m_asciiBuffer.append('/');
                         m_url.m_pathAfterLastSlash = m_asciiBuffer.size();
@@ -1203,8 +1198,10 @@
         case State::Host:
             LOG_STATE("Host");
             if (*c == '/' || *c == '?' || *c == '#') {
-                if (!parseHostAndPort(CodePointIterator<CharacterType>(authorityOrHostBegin, c)))
-                    return failure(input, length);
+                if (!parseHostAndPort(CodePointIterator<CharacterType>(authorityOrHostBegin, c))) {
+                    failure();
+                    return;
+                }
                 state = State::Path;
                 break;
             }
@@ -1307,7 +1304,7 @@
         case State::FileHost:
             LOG_STATE("FileHost");
             if (isSlashQuestionOrHash(*c)) {
-                if (isWindowsDriveLetter(m_asciiBuffer, m_url.m_portEnd + 1)) {
+                if (WebCore::isWindowsDriveLetter(m_asciiBuffer, m_url.m_portEnd + 1)) {
                     state = State::Path;
                     break;
                 }
@@ -1333,8 +1330,10 @@
                     state = State::Path;
                     break;
                 }
-                if (!parseHostAndPort(CodePointIterator<CharacterType>(authorityOrHostBegin, c)))
-                    return failure(input, length);
+                if (!parseHostAndPort(CodePointIterator<CharacterType>(authorityOrHostBegin, c))) {
+                    failure();
+                    return;
+                }
                 
                 if (StringView(m_asciiBuffer.data() + m_url.m_passwordEnd, m_asciiBuffer.size() - m_url.m_passwordEnd) == "localhost")  {
                     m_asciiBuffer.shrink(m_url.m_passwordEnd);
@@ -1445,12 +1444,16 @@
     switch (state) {
     case State::SchemeStart:
         LOG_FINAL_STATE("SchemeStart");
-        if (!m_asciiBuffer.size() && base.isValid())
-            return base;
-        return failure(input, length);
+        if (!m_asciiBuffer.size() && base.isValid()) {
+            m_url = base;
+            return;
+        }
+        failure();
+        return;
     case State::Scheme:
         LOG_FINAL_STATE("Scheme");
-        return failure(input, length);
+        failure();
+        return;
     case State::NoScheme:
         LOG_FINAL_STATE("NoScheme");
         RELEASE_ASSERT_NOT_REACHED();
@@ -1501,7 +1504,8 @@
         break;
     case State::SpecialAuthorityIgnoreSlashes:
         LOG_FINAL_STATE("SpecialAuthorityIgnoreSlashes");
-        return failure(input, length);
+        failure();
+        return;
         break;
     case State::AuthorityOrHost:
         LOG_FINAL_STATE("AuthorityOrHost");
@@ -1510,8 +1514,10 @@
         if (authorityOrHostBegin.atEnd()) {
             m_url.m_hostEnd = m_url.m_userEnd;
             m_url.m_portEnd = m_url.m_userEnd;
-        } else if (!parseHostAndPort(authorityOrHostBegin))
-            return failure(input, length);
+        } else if (!parseHostAndPort(authorityOrHostBegin)) {
+            failure();
+            return;
+        }
         m_asciiBuffer.append('/');
         m_url.m_pathEnd = m_url.m_portEnd + 1;
         m_url.m_pathAfterLastSlash = m_url.m_pathEnd;
@@ -1520,8 +1526,10 @@
         break;
     case State::Host:
         LOG_FINAL_STATE("Host");
-        if (!parseHostAndPort(authorityOrHostBegin))
-            return failure(input, length);
+        if (!parseHostAndPort(authorityOrHostBegin)) {
+            failure();
+            return;
+        }
         m_asciiBuffer.append('/');
         m_url.m_pathEnd = m_url.m_portEnd + 1;
         m_url.m_pathAfterLastSlash = m_url.m_pathEnd;
@@ -1574,8 +1582,10 @@
             break;
         }
 
-        if (!parseHostAndPort(CodePointIterator<CharacterType>(authorityOrHostBegin, c)))
-            return failure(input, length);
+        if (!parseHostAndPort(CodePointIterator<CharacterType>(authorityOrHostBegin, c))) {
+            failure();
+            return;
+        }
 
         if (StringView(m_asciiBuffer.data() + m_url.m_passwordEnd, m_asciiBuffer.size() - m_url.m_passwordEnd) == "localhost")  {
             m_asciiBuffer.shrink(m_url.m_passwordEnd);
@@ -1628,7 +1638,6 @@
     m_url.m_isValid = true;
     LOG(URLParser, "Parsed URL <%s>", m_url.m_string.utf8().data());
     ASSERT(internalValuesConsistent(m_url));
-    return m_url;
 }
 
 template<typename CharacterType>

Modified: trunk/Source/WebCore/platform/URLParser.h (206328 => 206329)


--- trunk/Source/WebCore/platform/URLParser.h	2016-09-23 20:33:53 UTC (rev 206328)
+++ trunk/Source/WebCore/platform/URLParser.h	2016-09-23 20:58:03 UTC (rev 206329)
@@ -36,7 +36,8 @@
 
 class URLParser {
 public:
-    WEBCORE_EXPORT URL parse(const String&, const URL& = { }, const TextEncoding& = UTF8Encoding());
+    WEBCORE_EXPORT URLParser(const String&, const URL& = { }, const TextEncoding& = UTF8Encoding());
+    URL result() { return m_url; }
 
     WEBCORE_EXPORT static bool allValuesEqual(const URL&, const URL&);
     WEBCORE_EXPORT static bool internalValuesConsistent(const URL&);
@@ -54,13 +55,20 @@
     Vector<UChar> m_unicodeFragmentBuffer;
     bool m_urlIsSpecial { false };
     bool m_hostHasPercentOrNonASCII { false };
+    String m_inputString;
 
-    template<typename CharacterType> URL parse(const CharacterType*, const unsigned length, const URL&, const TextEncoding&);
+    template<typename CharacterType> void parse(const CharacterType*, const unsigned length, const URL&, const TextEncoding&);
     template<typename CharacterType> void parseAuthority(CodePointIterator<CharacterType>);
     template<typename CharacterType> bool parseHostAndPort(CodePointIterator<CharacterType>);
     template<typename CharacterType> bool parsePort(CodePointIterator<CharacterType>&);
-    template<typename CharacterType> URL failure(const CharacterType*, unsigned length);
 
+    void failure();
+    template<typename CharacterType> void incrementIteratorSkippingTabAndNewLine(CodePointIterator<CharacterType>&);
+    template<typename CharacterType> void syntaxError(const CodePointIterator<CharacterType>&);
+    template<typename CharacterType> bool isWindowsDriveLetter(CodePointIterator<CharacterType>);
+    template<typename CharacterType> bool shouldCopyFileURL(CodePointIterator<CharacterType>);
+    template<typename CharacterType> void checkWindowsDriveLetter(CodePointIterator<CharacterType>&, Vector<LChar>& asciiBuffer);
+
     enum class URLPart;
     void copyURLPartsUntil(const URL& base, URLPart);
     static size_t urlLengthUntilPart(const URL&, URLPart);

Modified: trunk/Source/WebCore/platform/cf/URLCF.cpp (206328 => 206329)


--- trunk/Source/WebCore/platform/cf/URLCF.cpp	2016-09-23 20:33:53 UTC (rev 206328)
+++ trunk/Source/WebCore/platform/cf/URLCF.cpp	2016-09-23 20:58:03 UTC (rev 206329)
@@ -48,8 +48,8 @@
     CString urlBytes;
     getURLBytes(url, urlBytes);
     if (URLParser::enabled()) {
-        URLParser parser;
-        parser.parse(urlBytes.data());
+        URLParser parser(urlBytes.data());
+        *this = parser.result();
     } else
         parse(urlBytes.data());
 }

Modified: trunk/Source/WebCore/platform/mac/URLMac.mm (206328 => 206329)


--- trunk/Source/WebCore/platform/mac/URLMac.mm	2016-09-23 20:33:53 UTC (rev 206328)
+++ trunk/Source/WebCore/platform/mac/URLMac.mm	2016-09-23 20:58:03 UTC (rev 206329)
@@ -44,8 +44,8 @@
     CString urlBytes;
     getURLBytes(reinterpret_cast<CFURLRef>(url), urlBytes);
     if (URLParser::enabled()) {
-        URLParser parser;
-        *this = parser.parse(urlBytes.data());
+        URLParser parser(urlBytes.data());
+        *this = parser.result();
     } else
         parse(urlBytes.data());
 }

Modified: trunk/Tools/ChangeLog (206328 => 206329)


--- trunk/Tools/ChangeLog	2016-09-23 20:33:53 UTC (rev 206328)
+++ trunk/Tools/ChangeLog	2016-09-23 20:58:03 UTC (rev 206329)
@@ -1,3 +1,14 @@
+2016-09-23  Alex Christensen  <achristen...@webkit.org>
+
+        Refactor URLParser
+        https://bugs.webkit.org/show_bug.cgi?id=162511
+
+        Reviewed by Brady Eidson.
+
+        * TestWebKitAPI/Tests/WebCore/URLParser.cpp:
+        (TestWebKitAPI::TEST_F):
+        (TestWebKitAPI::checkURL):
+
 2016-09-23  Alexey Proskuryakov  <a...@apple.com>
 
         iOS playback user action tests fail on some machines

Modified: trunk/Tools/TestWebKitAPI/Tests/WebCore/URLParser.cpp (206328 => 206329)


--- trunk/Tools/TestWebKitAPI/Tests/WebCore/URLParser.cpp	2016-09-23 20:33:53 UTC (rev 206328)
+++ trunk/Tools/TestWebKitAPI/Tests/WebCore/URLParser.cpp	2016-09-23 20:58:03 UTC (rev 206329)
@@ -670,6 +670,9 @@
     checkURLDifferences("http://host/`",
         {"http", "", "", "host", 0, "/%60", "", "", "http://host/%60"},
         {"http", "", "", "host", 0, "/`", "", "", "http://host/`"});
+    checkURLDifferences(wideString(L"http://host/path#šŸ’©\tšŸ’©"),
+        {"http", "", "", "host", 0, "/path", "", wideString(L"šŸ’©šŸ’©"), wideString(L"http://host/path#šŸ’©šŸ’©")},
+        {"http", "", "", "host", 0, "/path", "", "%F0%9F%92%A9%F0%9F%92%A9", "http://host/path#%F0%9F%92%A9%F0%9F%92%A9"});
 }
     
 static void shouldFail(const String& urlString)
@@ -687,6 +690,7 @@
     shouldFail("    ");
     shouldFail("  \a  ");
     shouldFail("");
+    shouldFail(String());
     shouldFail("http://127.0.0.1:abc");
     shouldFail("http://host:abc");
     shouldFail("http://a:@", "about:blank");
@@ -758,8 +762,8 @@
 
 static void checkURL(const String& urlString, const TextEncoding& encoding, const ExpectedParts& parts)
 {
-    URLParser parser;
-    auto url = "" { }, encoding);
+    URLParser parser(urlString, { }, encoding);
+    auto url = ""
     EXPECT_TRUE(eq(parts.protocol, url.protocol()));
     EXPECT_TRUE(eq(parts.user, url.user()));
     EXPECT_TRUE(eq(parts.password, url.pass()));
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to