Changeset 205668 in webkit


Ignore:
Timestamp:
Sep 8, 2016, 3:16:49 PM (9 years ago)
Author:
achristensen@apple.com
Message:

URLParser should correctly handle \ in path
https://bugs.webkit.org/show_bug.cgi?id=161762

Reviewed by Brady Eidson.

Source/WebCore:

Covered by new API tests.

  • platform/URLParser.cpp:

(WebCore::isSpecialScheme):
(WebCore::bufferView):
(WebCore::URLParser::parse):
Treat \ as / in the path of special URLs as described in the spec and tested in web platform tests.
Also a slight performance improvement using StringViews instead of copied Strings.

Tools:

  • TestWebKitAPI/Tests/WebCore/URLParser.cpp:

(TestWebKitAPI::TEST_F):

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r205667 r205668  
     12016-09-08  Alex Christensen  <achristensen@webkit.org>
     2
     3        URLParser should correctly handle \ in path
     4        https://bugs.webkit.org/show_bug.cgi?id=161762
     5
     6        Reviewed by Brady Eidson.
     7
     8        Covered by new API tests.
     9
     10        * platform/URLParser.cpp:
     11        (WebCore::isSpecialScheme):
     12        (WebCore::bufferView):
     13        (WebCore::URLParser::parse):
     14        Treat \ as / in the path of special URLs as described in the spec and tested in web platform tests.
     15        Also a slight performance improvement using StringViews instead of copied Strings.
     16
    1172016-09-08  Alex Christensen  <achristensen@webkit.org>
    218
  • trunk/Source/WebCore/platform/URLParser.cpp

    r205667 r205668  
    140140}
    141141
    142 static bool isSpecialScheme(const String& scheme)
     142static bool isSpecialScheme(StringView scheme)
    143143{
    144144    return scheme == "ftp"
     
    149149        || scheme == "ws"
    150150        || scheme == "wss";
     151}
     152
     153static StringView bufferView(const StringBuilder& builder)
     154{
     155    if (builder.is8Bit())
     156        return StringView(builder.characters8(), builder.length());
     157    return StringView(builder.characters16(), builder.length());
    151158}
    152159
     
    395402#define LOG_FINAL_STATE(x) LOG(URLParser, "Final State: %s", x)
    396403
     404    bool urlIsSpecial = false;
    397405    State state = State::SchemeStart;
    398406    while (c != end) {
     
    418426            else if (*c == ':') {
    419427                m_url.m_schemeEnd = m_buffer.length();
    420                 String urlScheme = m_buffer.toString(); // FIXME: Find a way to do this without shrinking the m_buffer.
     428                StringView urlScheme = bufferView(m_buffer);
    421429                m_url.m_protocolIsInHTTPFamily = urlScheme == "http" || urlScheme == "https";
    422430                if (urlScheme == "file") {
     431                    urlIsSpecial = true;
    423432                    state = State::File;
    424433                    m_buffer.append(':');
     
    427436                }
    428437                if (isSpecialScheme(urlScheme)) {
     438                    urlIsSpecial = true;
    429439                    if (base.protocol() == urlScheme)
    430440                        state = State::SpecialRelativeOrAuthority;
     
    747757        case State::Path:
    748758            LOG_STATE("Path");
    749             if (*c == '/') {
     759            if (*c == '/' || (urlIsSpecial && *c == '\\')) {
    750760                m_buffer.append('/');
    751761                m_url.m_pathAfterLastSlash = m_buffer.length();
  • trunk/Tools/ChangeLog

    r205667 r205668  
     12016-09-08  Alex Christensen  <achristensen@webkit.org>
     2
     3        URLParser should correctly handle \ in path
     4        https://bugs.webkit.org/show_bug.cgi?id=161762
     5
     6        Reviewed by Brady Eidson.
     7
     8        * TestWebKitAPI/Tests/WebCore/URLParser.cpp:
     9        (TestWebKitAPI::TEST_F):
     10
    1112016-09-08  Alex Christensen  <achristensen@webkit.org>
    212
  • trunk/Tools/TestWebKitAPI/Tests/WebCore/URLParser.cpp

    r205667 r205668  
    238238    checkRelativeURL("http://@host", "about:blank", {"http", "", "", "host", 0, "/", "", "", "http://host/"});
    239239    checkRelativeURL("http://:@host", "about:blank", {"http", "", "", "host", 0, "/", "", "", "http://host/"});
     240    checkRelativeURL("http://foo.com/\\@", "http://example.org/foo/bar", {"http", "", "", "foo.com", 0, "//@", "", "", "http://foo.com//@"});
     241    checkRelativeURL("\\@", "http://example.org/foo/bar", {"http", "", "", "example.org", 0, "/@", "", "", "http://example.org/@"});
    240242}
    241243
Note: See TracChangeset for help on using the changeset viewer.