Changeset 206035 in webkit


Ignore:
Timestamp:
Sep 16, 2016 11:57:07 AM (8 years ago)
Author:
achristensen@apple.com
Message:

Fix more edge cases in URLParser
https://bugs.webkit.org/show_bug.cgi?id=162051

Reviewed by Tim Horton.

Source/WebCore:

Added new API tests.

  • platform/URLParser.cpp:

(WebCore::URLParser::parse):
Some edge case handling was wrong. Also, some of the terminal states are not possible
to reach because we transition to those states without incrementing the iterator.

Tools:

  • TestWebKitAPI/Tests/WebCore/URLParser.cpp:

(TestWebKitAPI::TEST_F):

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r206034 r206035  
     12016-09-16  Alex Christensen  <achristensen@webkit.org>
     2
     3        Fix more edge cases in URLParser
     4        https://bugs.webkit.org/show_bug.cgi?id=162051
     5
     6        Reviewed by Tim Horton.
     7
     8        Added new API tests.
     9
     10        * platform/URLParser.cpp:
     11        (WebCore::URLParser::parse):
     12        Some edge case handling was wrong. Also, some of the terminal states are not possible
     13        to reach because we transition to those states without incrementing the iterator.
     14
    1152016-09-16  Alex Christensen  <achristensen@webkit.org>
    216
  • trunk/Source/WebCore/platform/URLParser.cpp

    r205990 r206035  
    920920                if (isSpecialScheme(urlScheme)) {
    921921                    m_urlIsSpecial = true;
     922                    // FIXME: This is unnecessarily allocating a String.
     923                    // This should be easy to optimize once https://bugs.webkit.org/show_bug.cgi?id=162035 lands.
    922924                    if (base.protocol() == urlScheme)
    923925                        state = State::SpecialRelativeOrAuthority;
     
    10571059                while (!c.atEnd() && isTabOrNewline(*c))
    10581060                    ++c;
    1059                 if (c.atEnd())
    1060                     return failure(input, length);
    1061                 if (*c == '/' || *c == '\\')
     1061                if (!c.atEnd() && (*c == '/' || *c == '\\'))
    10621062                    ++c;
    10631063            }
     
    13481348    case State::Scheme:
    13491349        LOG_FINAL_STATE("Scheme");
    1350         break;
     1350        return failure(input, length);
    13511351    case State::NoScheme:
    13521352        LOG_FINAL_STATE("NoScheme");
    1353         break;
     1353        RELEASE_ASSERT_NOT_REACHED();
    13541354    case State::SpecialRelativeOrAuthority:
    13551355        LOG_FINAL_STATE("SpecialRelativeOrAuthority");
     
    13591359    case State::PathOrAuthority:
    13601360        LOG_FINAL_STATE("PathOrAuthority");
     1361        m_url.m_pathEnd = m_url.m_pathAfterLastSlash;
     1362        m_url.m_queryEnd = m_url.m_pathAfterLastSlash;
     1363        m_url.m_fragmentEnd = m_url.m_pathAfterLastSlash;
    13611364        break;
    13621365    case State::Relative:
     
    13881391        LOG_FINAL_STATE("SpecialAuthorityIgnoreSlashes");
    13891392        return failure(input, length);
     1393        break;
    13901394    case State::AuthorityOrHost:
    13911395        LOG_FINAL_STATE("AuthorityOrHost");
     
    14661470    case State::PathStart:
    14671471        LOG_FINAL_STATE("PathStart");
    1468         break;
     1472        RELEASE_ASSERT_NOT_REACHED();
    14691473    case State::Path:
    14701474        LOG_FINAL_STATE("Path");
  • trunk/Tools/ChangeLog

    r206033 r206035  
     12016-09-16  Alex Christensen  <achristensen@webkit.org>
     2
     3        Fix more edge cases in URLParser
     4        https://bugs.webkit.org/show_bug.cgi?id=162051
     5
     6        Reviewed by Tim Horton.
     7
     8        * TestWebKitAPI/Tests/WebCore/URLParser.cpp:
     9        (TestWebKitAPI::TEST_F):
     10
    1112016-09-16  Wenson Hsieh  <wenson_hsieh@apple.com>
    212
  • trunk/Tools/TestWebKitAPI/Tests/WebCore/URLParser.cpp

    r205988 r206035  
    204204    checkURL("sc://pa/", {"sc", "", "", "pa", 0, "/", "", "", "sc://pa/"});
    205205    checkURL("http://host   \a   ", {"http", "", "", "host", 0, "/", "", "", "http://host/"});
     206    checkURL("notspecial:/", {"notspecial", "", "", "", 0, "/", "", "", "notspecial:/"});
     207    checkURL("notspecial:/a", {"notspecial", "", "", "", 0, "/a", "", "", "notspecial:/a"});
     208    checkURL("notspecial:", {"notspecial", "", "", "", 0, "", "", "", "notspecial:"});
     209    checkURL("http:/a", {"http", "", "", "a", 0, "/", "", "", "http://a/"});
    206210    // FIXME: Fix and add a test with an invalid surrogate pair at the end with a space as the second code unit.
    207211
     
    280284    checkRelativeURL("  foo.com  ", "http://example.org/foo/bar", {"http", "", "", "example.org", 0, "/foo/foo.com", "", "", "http://example.org/foo/foo.com"});
    281285    checkRelativeURL(" \a baz", "http://example.org/foo/bar", {"http", "", "", "example.org", 0, "/foo/baz", "", "", "http://example.org/foo/baz"});
     286    checkRelativeURL("~", "http://example.org", {"http", "", "", "example.org", 0, "/~", "", "", "http://example.org/~"});
     287    checkRelativeURL("notspecial:/", "about:blank", {"notspecial", "", "", "", 0, "/", "", "", "notspecial:/"});
     288    checkRelativeURL("notspecial:", "about:blank", {"notspecial", "", "", "", 0, "", "", "", "notspecial:"});
     289    checkRelativeURL("notspecial:/", "http://host", {"notspecial", "", "", "", 0, "/", "", "", "notspecial:/"});
     290    checkRelativeURL("notspecial:", "http://host", {"notspecial", "", "", "", 0, "", "", "", "notspecial:"});
     291    checkRelativeURL("http:", "http://host", {"http", "", "", "host", 0, "/", "", "", "http://host/"});
    282292   
    283293    // The checking of slashes in SpecialAuthoritySlashes needed to get this to pass contradicts what is in the spec,
     
    447457        {"", "", "", "", 0, "", "", "", "file://notuser:notpassword@test/"},
    448458        {"file", "notuser", "notpassword", "test", 0, "/", "", "", "file://notuser:notpassword@test/"});
     459    checkRelativeURLDifferences("http:/", "about:blank",
     460        {"", "", "", "", 0, "", "", "", "http:/"},
     461        {"http", "", "", "", 0, "/", "", "", "http:/"});
     462    checkRelativeURLDifferences("http:", "about:blank",
     463        {"http", "", "", "", 0, "", "", "", "http:"},
     464        {"http", "", "", "", 0, "/", "", "", "http:/"});
     465    checkRelativeURLDifferences("http:/", "http://host",
     466        {"", "", "", "", 0, "", "", "", "http:/"},
     467        {"http", "", "", "", 0, "/", "", "", "http:/"});
     468    checkURLDifferences("http:/",
     469        {"", "", "", "", 0, "", "", "", "http:/"},
     470        {"http", "", "", "", 0, "/", "", "", "http:/"});
     471    checkURLDifferences("http:",
     472        {"http", "", "", "", 0, "", "", "", "http:"},
     473        {"http", "", "", "", 0, "/", "", "", "http:/"});
    449474   
    450475    // This behavior matches Chrome and Firefox, but not WebKit using URL::parse.
     
    573598{
    574599    shouldFail("    ");
     600    shouldFail("  \a  ");
    575601    shouldFail("");
    576602    shouldFail("http://127.0.0.1:abc");
     
    593619    shouldFail("http://192.168.0.1 hello", "http://other.com/");
    594620    shouldFail("http://[example.com]", "http://other.com/");
     621    shouldFail("i", "sc:sd");
     622    shouldFail("i", "sc:sd/sd");
     623    shouldFail("i");
     624    shouldFail("asdf");
     625    shouldFail("~");
     626    shouldFail("~", "about:blank");
     627    shouldFail("~~~");
    595628}
    596629
Note: See TracChangeset for help on using the changeset viewer.