Changeset 208086 in webkit


Ignore:
Timestamp:
Oct 28, 2016, 5:17:01 PM (9 years ago)
Author:
achristensen@apple.com
Message:

URLParser should not try to interpret host of URLs with unrecognized schemes as IPv4 address
https://bugs.webkit.org/show_bug.cgi?id=164154

Reviewed by Andy Estes.

Source/WebCore:

This is needed to match behavior of all browsers.
This is being discussed in the spec at https://github.com/whatwg/url/issues/148

Covered by new API tests.

  • platform/URLParser.cpp:

(WebCore::URLParser::parseHostAndPort):
Only try to parse and canonicalize the host as an IPv4 address if the scheme is special (http, wss, etc.)

Tools:

  • TestWebKitAPI/Tests/WebCore/URLParser.cpp:

(TestWebKitAPI::TEST_F):

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r208083 r208086  
     12016-10-28  Alex Christensen  <achristensen@webkit.org>
     2
     3        URLParser should not try to interpret host of URLs with unrecognized schemes as IPv4 address
     4        https://bugs.webkit.org/show_bug.cgi?id=164154
     5
     6        Reviewed by Andy Estes.
     7
     8        This is needed to match behavior of all browsers.
     9        This is being discussed in the spec at https://github.com/whatwg/url/issues/148
     10
     11        Covered by new API tests.
     12
     13        * platform/URLParser.cpp:
     14        (WebCore::URLParser::parseHostAndPort):
     15        Only try to parse and canonicalize the host as an IPv4 address if the scheme is special (http, wss, etc.)
     16
    1172016-10-28  Chris Dumez  <cdumez@apple.com>
    218
  • trunk/Source/WebCore/platform/URLParser.cpp

    r207805 r208086  
    25732573                return false;
    25742574        }
    2575         if (auto address = parseIPv4Host(CodePointIterator<CharacterType>(hostIterator, iterator))) {
    2576             serializeIPv4(address.value());
    2577             m_url.m_hostEnd = currentPosition(iterator);
    2578             if (iterator.atEnd()) {
    2579                 m_url.m_portEnd = currentPosition(iterator);
    2580                 return true;
    2581             }
    2582             return parsePort(iterator);
     2575        if (m_urlIsSpecial) {
     2576            if (auto address = parseIPv4Host(CodePointIterator<CharacterType>(hostIterator, iterator))) {
     2577                serializeIPv4(address.value());
     2578                m_url.m_hostEnd = currentPosition(iterator);
     2579                if (iterator.atEnd()) {
     2580                    m_url.m_portEnd = currentPosition(iterator);
     2581                    return true;
     2582                }
     2583                return parsePort(iterator);
     2584            }
    25832585        }
    25842586        for (; hostIterator != iterator; ++hostIterator) {
    2585             if (LIKELY(!isTabOrNewline(*hostIterator))) {
    2586                 if (m_urlIsSpecial) {
    2587                     if (UNLIKELY(isASCIIUpper(*hostIterator)))
    2588                         syntaxViolation(hostIterator);
    2589                     appendToASCIIBuffer(toASCIILower(*hostIterator));
    2590                 } else
    2591                     appendToASCIIBuffer(*hostIterator);
     2587            if (UNLIKELY(isTabOrNewline(*hostIterator))) {
     2588                syntaxViolation(hostIterator);
     2589                continue;
     2590            }
     2591            if (m_urlIsSpecial) {
     2592                if (UNLIKELY(isASCIIUpper(*hostIterator)))
     2593                    syntaxViolation(hostIterator);
     2594                appendToASCIIBuffer(toASCIILower(*hostIterator));
    25922595            } else
    2593                 syntaxViolation(hostIterator);
     2596                appendToASCIIBuffer(*hostIterator);
    25942597        }
    25952598        m_url.m_hostEnd = currentPosition(iterator);
  • trunk/Tools/ChangeLog

    r208066 r208086  
     12016-10-28  Alex Christensen  <achristensen@webkit.org>
     2
     3        URLParser should not try to interpret host of URLs with unrecognized schemes as IPv4 address
     4        https://bugs.webkit.org/show_bug.cgi?id=164154
     5
     6        Reviewed by Andy Estes.
     7
     8        * TestWebKitAPI/Tests/WebCore/URLParser.cpp:
     9        (TestWebKitAPI::TEST_F):
     10
    1112016-10-28  Sam Weinig  <sam@webkit.org>
    212
  • trunk/Tools/TestWebKitAPI/Tests/WebCore/URLParser.cpp

    r207805 r208086  
    950950        {"", "", "", "", 0, "", "", "", "http://[a:b:c:d:e:f::127.0.0.256]"},
    951951        {"http", "", "", "[a:b:c:d:e:f::127.0.0.256]", 0, "/", "", "", "http://[a:b:c:d:e:f::127.0.0.256]/"});
     952    checkURLDifferences("http://123456", {"http", "", "", "0.1.226.64", 0, "/", "", "", "http://0.1.226.64/"}, {"http", "", "", "123456", 0, "/", "", "", "http://123456/"});
     953    checkURL("asdf://123456", {"asdf", "", "", "123456", 0, "", "", "", "asdf://123456"});
     954    checkURLDifferences("http://[0:0:0:0:a:b:c:d]",
     955        {"http", "", "", "[::a:b:c:d]", 0, "/", "", "", "http://[::a:b:c:d]/"},
     956        {"http", "", "", "[0:0:0:0:a:b:c:d]", 0, "/", "", "", "http://[0:0:0:0:a:b:c:d]/"});
     957    checkURLDifferences("asdf://[0:0:0:0:a:b:c:d]",
     958        {"asdf", "", "", "[::a:b:c:d]", 0, "", "", "", "asdf://[::a:b:c:d]"},
     959        {"asdf", "", "", "[0:0:0:0:a:b:c:d]", 0, "", "", "", "asdf://[0:0:0:0:a:b:c:d]"});
    952960}
    953961
     
    11061114    shouldFail("http://[a:b:c:d:e:f:127.0.-0.1]");
    11071115    shouldFail("asdf://space InHost");
     1116    shouldFail("asdf://[0:0:0:0:a:b:c:d");
    11081117}
    11091118
Note: See TracChangeset for help on using the changeset viewer.