Changeset 206942 in webkit


Ignore:
Timestamp:
Oct 7, 2016, 4:06:32 PM (9 years ago)
Author:
achristensen@apple.com
Message:

Non-special URL fragments should percent-encode non-ASCII characters
https://bugs.webkit.org/show_bug.cgi?id=163153

Reviewed by Tim Horton.

Source/WebCore:

This is needed to keep compatibility with data URLs with non-ASCII characters after a '#'
which works in Chrome, Firefox, and Safari, while maintaining compatibility with Chrome, IE, and Edge
which keep non-ASCII characters in the fragments of special URLs.
This was proposed to the spec in https://github.com/whatwg/url/issues/150

Covered by new API tests.

  • platform/URLParser.cpp:

(WebCore::URLParser::syntaxViolation):
Removed assertion because we now have fragments that need percent encoding but are all ASCII.
(WebCore::URLParser::fragmentSyntaxViolation):
(WebCore::URLParser::parse):

Tools:

  • TestWebKitAPI/Tests/WebCore/URLParser.cpp:

(TestWebKitAPI::TEST_F):

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r206941 r206942  
     12016-10-07  Alex Christensen  <achristensen@webkit.org>
     2
     3        Non-special URL fragments should percent-encode non-ASCII characters
     4        https://bugs.webkit.org/show_bug.cgi?id=163153
     5
     6        Reviewed by Tim Horton.
     7
     8        This is needed to keep compatibility with data URLs with non-ASCII characters after a '#'
     9        which works in Chrome, Firefox, and Safari, while maintaining compatibility with Chrome, IE, and Edge
     10        which keep non-ASCII characters in the fragments of special URLs.
     11        This was proposed to the spec in https://github.com/whatwg/url/issues/150
     12
     13        Covered by new API tests.
     14
     15        * platform/URLParser.cpp:
     16        (WebCore::URLParser::syntaxViolation):
     17        Removed assertion because we now have fragments that need percent encoding but are all ASCII.
     18        (WebCore::URLParser::fragmentSyntaxViolation):
     19        (WebCore::URLParser::parse):
     20
    1212016-10-07  Brent Fulgham  <bfulgham@apple.com>
    222
  • trunk/Source/WebCore/platform/URLParser.cpp

    r206924 r206942  
    10201020    ASSERT(m_asciiBuffer.isEmpty());
    10211021    ASSERT(m_unicodeFragmentBuffer.isEmpty());
    1022     ASSERT_WITH_MESSAGE(!m_url.m_queryEnd, "syntaxViolation should not be used in the fragment, which might contain non-ASCII code points when serialized");
    10231022    size_t codeUnitsToCopy = iterator.codeUnitsSince(reinterpret_cast<const CharacterType*>(m_inputBegin));
    10241023    RELEASE_ASSERT(codeUnitsToCopy <= m_inputString.length());
     
    10331032void URLParser::fragmentSyntaxViolation(const CodePointIterator<CharacterType>& iterator)
    10341033{
     1034    ASSERT(m_didSeeUnicodeFragmentCodePoint);
    10351035    if (m_didSeeSyntaxViolation)
    10361036        return;
    10371037    m_didSeeSyntaxViolation = true;
    1038     m_didSeeUnicodeFragmentCodePoint = true;
    10391038
    10401039    ASSERT(m_asciiBuffer.isEmpty());
     
    18151814            do {
    18161815                URL_PARSER_LOG("State Fragment");
    1817                 if (!m_didSeeUnicodeFragmentCodePoint && isASCII(*c))
    1818                     appendToASCIIBuffer(*c);
    1819                 else {
    1820                     m_didSeeUnicodeFragmentCodePoint = true;
    1821                     if (UNLIKELY(m_didSeeSyntaxViolation))
    1822                         appendCodePoint(m_unicodeFragmentBuffer, *c);
    1823                     else {
    1824                         ASSERT(m_asciiBuffer.isEmpty());
    1825                         ASSERT(m_unicodeFragmentBuffer.isEmpty());
    1826                     }
     1816                if (!c.atEnd() && isTabOrNewline(*c)) {
     1817                    if (m_didSeeUnicodeFragmentCodePoint)
     1818                        fragmentSyntaxViolation(c);
     1819                    else
     1820                        syntaxViolation(c);
     1821                    ++c;
     1822                    continue;
     1823                }
     1824                if (!m_didSeeUnicodeFragmentCodePoint && isASCII(*c)) {
     1825                    if (m_urlIsSpecial)
     1826                        appendToASCIIBuffer(*c);
     1827                    else
     1828                        utf8PercentEncode<isInSimpleEncodeSet>(c);
     1829                } else {
     1830                    if (m_urlIsSpecial) {
     1831                        m_didSeeUnicodeFragmentCodePoint = true;
     1832                        if (UNLIKELY(m_didSeeSyntaxViolation))
     1833                            appendCodePoint(m_unicodeFragmentBuffer, *c);
     1834                        else {
     1835                            ASSERT(m_asciiBuffer.isEmpty());
     1836                            ASSERT(m_unicodeFragmentBuffer.isEmpty());
     1837                        }
     1838                    } else
     1839                        utf8PercentEncode<isInSimpleEncodeSet>(c);
    18271840                }
    18281841                ++c;
    1829                 while (UNLIKELY(!c.atEnd() && isTabOrNewline(*c))) {
    1830                     fragmentSyntaxViolation(c);
    1831                     ++c;
    1832                 }
    18331842            } while (!c.atEnd());
    18341843            break;
  • trunk/Tools/ChangeLog

    r206940 r206942  
     12016-10-07  Alex Christensen  <achristensen@webkit.org>
     2
     3        Non-special URL fragments should percent-encode non-ASCII characters
     4        https://bugs.webkit.org/show_bug.cgi?id=163153
     5
     6        Reviewed by Tim Horton.
     7
     8        * TestWebKitAPI/Tests/WebCore/URLParser.cpp:
     9        (TestWebKitAPI::TEST_F):
     10
    1112016-10-07  Jonathan Bedard  <jbedard@apple.com>
    212
  • trunk/Tools/TestWebKitAPI/Tests/WebCore/URLParser.cpp

    r206887 r206942  
    330330    checkURL("A://", {"a", "", "", "", 0, "//", "", "", "a://"});
    331331    checkURL("aA://", {"aa", "", "", "", 0, "//", "", "", "aa://"});
     332    checkURL(utf16String(u"foo://host/#ПП\u0007 a</"), {"foo", "", "", "host", 0, "/", "", "%D0%9F%D0%9F%07 a</", "foo://host/#%D0%9F%D0%9F%07 a</"});
     333    checkURL(utf16String(u"foo://host/#\u0007 a</"), {"foo", "", "", "host", 0, "/", "", "%07 a</", "foo://host/#%07 a</"});
    332334
    333335    // This disagrees with the web platform test for http://:@www.example.com but agrees with Chrome and URL::parse,
     
    10591061        {"", "", "", "", 0, "", "", "", "file://:0/path"},
    10601062        {"file", "", "", "", 0, "/path", "", "", "file://:0/path"});
     1063    checkURLDifferences(utf16String(u"http://host/#ПП\u0007 a</"),
     1064        {"http", "", "", "host", 0, "/", "", utf16String(u"ПП\u0007 a</"), utf16String(u"http://host/#ПП\u0007 a</")},
     1065        {"http", "", "", "host", 0, "/", "", "%D0%9F%D0%9F%07 a</", "http://host/#%D0%9F%D0%9F%07 a</"});
     1066    checkURLDifferences(utf16String(u"http://host/#\u0007 a</"),
     1067        {"http", "", "", "host", 0, "/", "", "\a a</", "http://host/#\a a</"},
     1068        {"http", "", "", "host", 0, "/", "", "%07 a</", "http://host/#%07 a</"});
    10611069}
    10621070   
Note: See TracChangeset for help on using the changeset viewer.