Title: [206735] trunk
Revision
206735
Author
[email protected]
Date
2016-10-03 10:28:04 -0700 (Mon, 03 Oct 2016)

Log Message

URLParser: empty relative URLs should not copy fragment from the base URL
https://bugs.webkit.org/show_bug.cgi?id=162864

Reviewed by Chris Dumez.

Source/WebCore:

Covered by new API tests.

* platform/URL.cpp:
(WebCore::URL::removeFragmentIdentifier):
Optimize removing fragments, now that it happens more often. We don't need to reparse, 
because the result will always be equal to just a substring when removing the fragment at the end.
* platform/URLParser.cpp:
(WebCore::URLParser::copyASCIIStringUntil):
(WebCore::URLParser::copyURLPartsUntil):
(WebCore::containsOnlyC0ControlOrSpace):
(WebCore::URLParser::URLParser):
(WebCore::URLParser::parse):
* platform/URLParser.h:
Because we are not copying the fragment, we can simplify and remove some unreachable code.

Tools:

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

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (206734 => 206735)


--- trunk/Source/WebCore/ChangeLog	2016-10-03 16:43:03 UTC (rev 206734)
+++ trunk/Source/WebCore/ChangeLog	2016-10-03 17:28:04 UTC (rev 206735)
@@ -1,3 +1,25 @@
+2016-10-03  Alex Christensen  <[email protected]>
+
+        URLParser: empty relative URLs should not copy fragment from the base URL
+        https://bugs.webkit.org/show_bug.cgi?id=162864
+
+        Reviewed by Chris Dumez.
+
+        Covered by new API tests.
+
+        * platform/URL.cpp:
+        (WebCore::URL::removeFragmentIdentifier):
+        Optimize removing fragments, now that it happens more often. We don't need to reparse, 
+        because the result will always be equal to just a substring when removing the fragment at the end.
+        * platform/URLParser.cpp:
+        (WebCore::URLParser::copyASCIIStringUntil):
+        (WebCore::URLParser::copyURLPartsUntil):
+        (WebCore::containsOnlyC0ControlOrSpace):
+        (WebCore::URLParser::URLParser):
+        (WebCore::URLParser::parse):
+        * platform/URLParser.h:
+        Because we are not copying the fragment, we can simplify and remove some unreachable code.
+
 2016-10-03  Chris Dumez  <[email protected]>
 
         td.scope should only return known values

Modified: trunk/Source/WebCore/platform/URL.cpp (206734 => 206735)


--- trunk/Source/WebCore/platform/URL.cpp	2016-10-03 16:43:03 UTC (rev 206734)
+++ trunk/Source/WebCore/platform/URL.cpp	2016-10-03 17:28:04 UTC (rev 206735)
@@ -1106,14 +1106,14 @@
 
 void URL::removeFragmentIdentifier()
 {
-    if (!m_isValid)
+    if (!m_isValid) {
+        ASSERT(!m_fragmentEnd);
+        ASSERT(!m_queryEnd);
         return;
-    if (URLParser::enabled()) {
-        // FIXME: We shouldn't need to parse here.
-        URLParser parser(m_string.left(m_queryEnd));
-        *this = parser.result();
-    } else
-        parse(m_string.left(m_queryEnd));
+    }
+    if (m_fragmentEnd > m_queryEnd)
+        m_string = m_string.left(m_queryEnd);
+    m_fragmentEnd = m_queryEnd;
 }
     
 void URL::setQuery(const String& query)

Modified: trunk/Source/WebCore/platform/URLParser.cpp (206734 => 206735)


--- trunk/Source/WebCore/platform/URLParser.cpp	2016-10-03 16:43:03 UTC (rev 206734)
+++ trunk/Source/WebCore/platform/URLParser.cpp	2016-10-03 17:28:04 UTC (rev 206735)
@@ -758,21 +758,17 @@
     return 0;
 }
 
-void URLParser::copyASCIIStringUntil(const String& string, size_t lengthIf8Bit, size_t lengthIf16Bit)
+void URLParser::copyASCIIStringUntil(const String& string, size_t length)
 {
-    if (string.isNull()) {
-        ASSERT(!lengthIf8Bit);
-        ASSERT(!lengthIf16Bit);
+    RELEASE_ASSERT(length <= string.length());
+    if (string.isNull())
         return;
-    }
     ASSERT(m_asciiBuffer.isEmpty());
     if (string.is8Bit()) {
-        RELEASE_ASSERT(lengthIf8Bit <= string.length());
-        appendToASCIIBuffer(string.characters8(), lengthIf8Bit);
+        appendToASCIIBuffer(string.characters8(), length);
     } else {
-        RELEASE_ASSERT(lengthIf16Bit <= string.length());
         const UChar* characters = string.characters16();
-        for (size_t i = 0; i < lengthIf16Bit; ++i) {
+        for (size_t i = 0; i < length; ++i) {
             UChar c = characters[i];
             ASSERT_WITH_SECURITY_IMPLICATION(isASCII(c));
             appendToASCIIBuffer(c);
@@ -787,28 +783,10 @@
 
     m_asciiBuffer.clear();
     m_unicodeFragmentBuffer.clear();
-    if (part == URLPart::FragmentEnd) {
-        copyASCIIStringUntil(base.m_string, urlLengthUntilPart(base, URLPart::FragmentEnd), urlLengthUntilPart(base, URLPart::QueryEnd));
-        if (!base.m_string.is8Bit()) {
-            const String& fragment = base.m_string;
-            bool seenUnicode = false;
-            for (size_t i = base.m_queryEnd; i < base.m_fragmentEnd; ++i) {
-                if (!seenUnicode && !isASCII(fragment[i]))
-                    seenUnicode = true;
-                if (seenUnicode)
-                    m_unicodeFragmentBuffer.uncheckedAppend(fragment[i]);
-                else
-                    m_asciiBuffer.uncheckedAppend(fragment[i]);
-            }
-        }
-    } else {
-        size_t length = urlLengthUntilPart(base, part);
-        copyASCIIStringUntil(base.m_string, length, length);
-    }
+    copyASCIIStringUntil(base.m_string, urlLengthUntilPart(base, part));
     switch (part) {
     case URLPart::FragmentEnd:
-        m_url.m_fragmentEnd = base.m_fragmentEnd;
-        FALLTHROUGH;
+        RELEASE_ASSERT_NOT_REACHED();
     case URLPart::QueryEnd:
         m_url.m_queryEnd = base.m_queryEnd;
         FALLTHROUGH;
@@ -1082,8 +1060,10 @@
     : m_inputString(input)
 {
     if (input.isNull()) {
-        if (base.isValid() && !base.m_cannotBeABaseURL)
+        if (base.isValid() && !base.m_cannotBeABaseURL) {
             m_url = base;
+            m_url.removeFragmentIdentifier();
+        }
         return;
     }
 
@@ -1097,7 +1077,8 @@
 
     ASSERT(!m_url.m_isValid
         || m_didSeeSyntaxViolation == (m_url.string() != input)
-        || (input.isEmpty() && m_url.m_string == base.m_string));
+        || (input.isAllSpecialCharacters<isC0ControlOrSpace>()
+            && m_url.m_string == base.m_string.left(base.m_queryEnd)));
     ASSERT(internalValuesConsistent(m_url));
 #if !ASSERT_DISABLED
     if (!m_didSeeSyntaxViolation) {
@@ -1755,6 +1736,7 @@
         LOG_FINAL_STATE("SchemeStart");
         if (!currentPosition(c) && base.isValid() && !base.m_cannotBeABaseURL) {
             m_url = base;
+            m_url.removeFragmentIdentifier();
             return;
         }
         failure();
@@ -1788,8 +1770,7 @@
         break;
     case State::Relative:
         LOG_FINAL_STATE("Relative");
-        copyURLPartsUntil(base, URLPart::FragmentEnd, c);
-        break;
+        RELEASE_ASSERT_NOT_REACHED();
     case State::RelativeSlash:
         LOG_FINAL_STATE("RelativeSlash");
         copyURLPartsUntil(base, URLPart::PortEnd, c);

Modified: trunk/Source/WebCore/platform/URLParser.h (206734 => 206735)


--- trunk/Source/WebCore/platform/URLParser.h	2016-10-03 16:43:03 UTC (rev 206734)
+++ trunk/Source/WebCore/platform/URLParser.h	2016-10-03 17:28:04 UTC (rev 206735)
@@ -93,7 +93,7 @@
     void appendToASCIIBuffer(const char*, size_t);
     void appendToASCIIBuffer(const LChar* characters, size_t size) { appendToASCIIBuffer(reinterpret_cast<const char*>(characters), size); }
     template<typename CharacterType> void encodeQuery(const Vector<UChar>& source, const TextEncoding&, CodePointIterator<CharacterType>);
-    void copyASCIIStringUntil(const String&, size_t lengthIf8Bit, size_t lengthIf16Bit);
+    void copyASCIIStringUntil(const String&, size_t length);
     StringView parsedDataView(size_t start, size_t length);
 
     using IPv4Address = uint32_t;

Modified: trunk/Tools/ChangeLog (206734 => 206735)


--- trunk/Tools/ChangeLog	2016-10-03 16:43:03 UTC (rev 206734)
+++ trunk/Tools/ChangeLog	2016-10-03 17:28:04 UTC (rev 206735)
@@ -1,3 +1,13 @@
+2016-10-03  Alex Christensen  <[email protected]>
+
+        URLParser: empty relative URLs should not copy fragment from the base URL
+        https://bugs.webkit.org/show_bug.cgi?id=162864
+
+        Reviewed by Chris Dumez.
+
+        * TestWebKitAPI/Tests/WebCore/URLParser.cpp:
+        (TestWebKitAPI::TEST_F):
+
 2016-10-03  Carlos Garcia Campos  <[email protected]>
 
         [SOUP] Cleanup persistent credential storage code

Modified: trunk/Tools/TestWebKitAPI/Tests/WebCore/URLParser.cpp (206734 => 206735)


--- trunk/Tools/TestWebKitAPI/Tests/WebCore/URLParser.cpp	2016-10-03 16:43:03 UTC (rev 206734)
+++ trunk/Tools/TestWebKitAPI/Tests/WebCore/URLParser.cpp	2016-10-03 17:28:04 UTC (rev 206735)
@@ -404,6 +404,11 @@
     checkRelativeURL(String(), "http://webkit.org/", {"http", "", "", "webkit.org", 0, "/", "", "", "http://webkit.org/"});
     checkRelativeURL("https://@test@test@example:800\\path@end", "http://doesnotmatter/", {"", "", "", "", 0, "", "", "", "https://@test@test@example:800\\path@end"});
     checkRelativeURL("http://f:0/c", "http://example.org/foo/bar", {"http", "", "", "f", 0, "/c", "", "", "http://f:0/c"});
+    checkRelativeURL(String(), "http://host/#fragment", {"http", "", "", "host", 0, "/", "", "", "http://host/"});
+    checkRelativeURL("", "http://host/#fragment", {"http", "", "", "host", 0, "/", "", "", "http://host/"});
+    checkRelativeURL("  ", "http://host/#fragment", {"http", "", "", "host", 0, "/", "", "", "http://host/"});
+    checkRelativeURL("  ", "http://host/path?query#fra#gment", {"http", "", "", "host", 0, "/path", "query", "", "http://host/path?query"});
+    checkRelativeURL(" \a ", "http://host/#fragment", {"http", "", "", "host", 0, "/", "", "", "http://host/"});
 
     // The checking of slashes in SpecialAuthoritySlashes needed to get this to pass contradicts what is in the spec,
     // but it is included in the web platform tests.
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to