Changeset 205650 in webkit


Ignore:
Timestamp:
Sep 8, 2016 10:23:30 AM (8 years ago)
Author:
achristensen@apple.com
Message:

Re-land r205580 after r205649 fixed the test failures
https://bugs.webkit.org/show_bug.cgi?id=161668

Re-landing changesets:

"Punycode encode non-ascii hosts in URLParser"
https://bugs.webkit.org/show_bug.cgi?id=161655
http://trac.webkit.org/changeset/205521

"Fix query-only and fragment-only relative URLs when using
URLParser"
https://bugs.webkit.org/show_bug.cgi?id=161657
http://trac.webkit.org/changeset/205526

"URLParser should parse / as a relative URL"
https://bugs.webkit.org/show_bug.cgi?id=161667
http://trac.webkit.org/changeset/205532

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r205649 r205650  
     12016-09-08  Alex Christensen  <achristensen@webkit.org>
     2
     3        Re-land r205580 after r205649 fixed the test failures
     4        https://bugs.webkit.org/show_bug.cgi?id=161668
     5
     6        Re-landing changesets:
     7
     8        "Punycode encode non-ascii hosts in URLParser"
     9        https://bugs.webkit.org/show_bug.cgi?id=161655
     10        http://trac.webkit.org/changeset/205521
     11
     12        "Fix query-only and fragment-only relative URLs when using
     13        URLParser"
     14        https://bugs.webkit.org/show_bug.cgi?id=161657
     15        http://trac.webkit.org/changeset/205526
     16
     17        "URLParser should parse / as a relative URL"
     18        https://bugs.webkit.org/show_bug.cgi?id=161667
     19        http://trac.webkit.org/changeset/205532
     20
    1212016-09-08  Alex Christensen  <achristensen@webkit.org>
    222
  • trunk/Source/WebCore/platform/URLParser.cpp

    r205649 r205650  
    2929#include "Logging.h"
    3030#include <array>
     31#include <unicode/uidna.h>
    3132#include <wtf/HashMap.h>
    3233#include <wtf/NeverDestroyed.h>
     
    451452            LOG_STATE("SchemeEndCheckForSlashes");
    452453            if (*c == '/') {
    453                 m_buffer.append('/');
     454                m_buffer.append("//");
     455                m_url.m_userStart = m_buffer.length();
    454456                state = State::PathOrAuthority;
    455457                ++c;
     
    516518            case '?':
    517519                copyURLPartsUntil(base, URLPart::PathEnd);
     520                m_buffer.append('?');
    518521                state = State::Query;
    519522                ++c;
     
    521524            case '#':
    522525                copyURLPartsUntil(base, URLPart::QueryEnd);
     526                m_buffer.append('#');
    523527                state = State::Fragment;
    524528                ++c;
     
    842846    case State::RelativeSlash:
    843847        LOG_FINAL_STATE("RelativeSlash");
     848        copyURLPartsUntil(base, URLPart::PortEnd);
     849        m_buffer.append('/');
     850        m_url.m_pathAfterLastSlash = base.m_portEnd + 1;
     851        m_url.m_pathEnd = m_url.m_pathAfterLastSlash;
     852        m_url.m_queryEnd = m_url.m_pathAfterLastSlash;
     853        m_url.m_fragmentEnd = m_url.m_pathAfterLastSlash;
    844854        break;
    845855    case State::SpecialAuthoritySlashes:
     
    12701280}
    12711281
     1282static bool containsOnlyASCII(const String& string)
     1283{
     1284    if (string.is8Bit())
     1285        return charactersAreAllASCII(string.characters8(), string.length());
     1286    return charactersAreAllASCII(string.characters16(), string.length());
     1287}
     1288
    12721289static Optional<String> domainToASCII(const String& domain)
    12731290{
    1274     // FIXME: Implement correctly
    1275     CString utf8 = domain.utf8();
    1276     return String(utf8.data(), utf8.length());
     1291    const unsigned hostnameBufferLength = 2048;
     1292
     1293    if (containsOnlyASCII(domain)) {
     1294        if (domain.is8Bit())
     1295            return domain;
     1296        Vector<LChar, hostnameBufferLength> buffer;
     1297        size_t length = domain.length();
     1298        buffer.reserveInitialCapacity(length);
     1299        for (size_t i = 0; i < length; ++i)
     1300            buffer.append(domain[i]);
     1301        return String(buffer.data(), length);
     1302    }
     1303   
     1304    UChar hostnameBuffer[hostnameBufferLength];
     1305    UErrorCode error = U_ZERO_ERROR;
     1306   
     1307    int32_t numCharactersConverted = uidna_IDNToASCII(StringView(domain).upconvertedCharacters(), domain.length(), hostnameBuffer, hostnameBufferLength, UIDNA_ALLOW_UNASSIGNED, nullptr, &error);
     1308
     1309    if (error == U_ZERO_ERROR) {
     1310        LChar buffer[hostnameBufferLength];
     1311        for (int32_t i = 0; i < numCharactersConverted; ++i) {
     1312            ASSERT(isASCII(hostnameBuffer[i]));
     1313            buffer[i] = hostnameBuffer[i];
     1314        }
     1315        return String(buffer, numCharactersConverted);
     1316    }
     1317
     1318    // FIXME: Check for U_BUFFER_OVERFLOW_ERROR and retry with an allocated buffer.
     1319    return Nullopt;
    12771320}
    12781321
  • trunk/Tools/ChangeLog

    r205618 r205650  
     12016-09-08  Alex Christensen  <achristensen@webkit.org>
     2
     3        Re-land r205580 after r205649 fixed the test failures
     4        https://bugs.webkit.org/show_bug.cgi?id=161668
     5
     6        Re-landing changesets:
     7
     8        "Punycode encode non-ascii hosts in URLParser"
     9        https://bugs.webkit.org/show_bug.cgi?id=161655
     10        http://trac.webkit.org/changeset/205521
     11
     12        "Fix query-only and fragment-only relative URLs when using
     13        URLParser"
     14        https://bugs.webkit.org/show_bug.cgi?id=161657
     15        http://trac.webkit.org/changeset/205526
     16
     17        "URLParser should parse / as a relative URL"
     18        https://bugs.webkit.org/show_bug.cgi?id=161667
     19        http://trac.webkit.org/changeset/205532
     20
    1212016-09-08  Dean Jackson  <dino@apple.com>
    222
  • trunk/Tools/TestWebKitAPI/Tests/WebCore/URLParser.cpp

    r205584 r205650  
    8383   
    8484    EXPECT_TRUE(URLParser::allValuesEqual(url, oldURL));
     85}
     86
     87template<size_t length>
     88static String wideString(const wchar_t (&url)[length])
     89{
     90    StringBuilder builder;
     91    builder.reserveCapacity(length - 1);
     92    for (size_t i = 0; i < length - 1; ++i)
     93        builder.append(url[i]);
     94    return builder.toString();
    8595}
    8696
     
    210220    checkRelativeURL("http://example\t.\norg", "http://example.org/foo/bar", {"http", "", "", "example.org", 0, "/", "", "", "http://example.org/"});
    211221    checkRelativeURL("test", "file:///path1/path2", {"file", "", "", "", 0, "/path1/test", "", "", "file:///path1/test"});
     222    checkRelativeURL(wideString(L"http://www.foo。bar.com"), "http://other.com/", {"http", "", "", "www.foo.bar.com", 0, "/", "", "", "http://www.foo.bar.com/"});
     223    checkRelativeURL(wideString(L"sc://ñ.test/"), "about:blank", {"sc", "", "", "xn--ida.test", 0, "/", "", "", "sc://xn--ida.test/"});
     224    checkRelativeURL("#fragment", "http://host/path", {"http", "", "", "host", 0, "/path", "", "fragment", "http://host/path#fragment"});
     225    checkRelativeURL("?query", "http://host/path", {"http", "", "", "host", 0, "/path", "query", "", "http://host/path?query"});
     226    checkRelativeURL("?query#fragment", "http://host/path", {"http", "", "", "host", 0, "/path", "query", "fragment", "http://host/path?query#fragment"});
     227    checkRelativeURL(wideString(L"?β"), "http://example.org/foo/bar", {"http", "", "", "example.org", 0, "/foo/bar", "%CE%B2", "", "http://example.org/foo/bar?%CE%B2"});
     228    checkRelativeURL("?", "http://example.org/foo/bar", {"http", "", "", "example.org", 0, "/foo/bar", "", "", "http://example.org/foo/bar?"});
     229    checkRelativeURL("#", "http://example.org/foo/bar", {"http", "", "", "example.org", 0, "/foo/bar", "", "", "http://example.org/foo/bar#"});
     230    checkRelativeURL("?#", "http://example.org/foo/bar", {"http", "", "", "example.org", 0, "/foo/bar", "", "", "http://example.org/foo/bar?#"});
     231    checkRelativeURL("#?", "http://example.org/foo/bar", {"http", "", "", "example.org", 0, "/foo/bar", "", "?", "http://example.org/foo/bar#?"});
     232    checkRelativeURL("/", "http://example.org/foo/bar", {"http", "", "", "example.org", 0, "/", "", "", "http://example.org/"});
    212233}
    213234
     
    331352        {"file", "", "", "[0:a::b:c:0:0]", 0, "/path", "", "", "file://[0:a::b:c:0:0]/path"},
    332353        {"file", "", "", "[0:a:0:0:b:c:0:0]", 0, "/path", "", "", "file://[0:a:0:0:b:c:0:0]/path"});
     354    checkRelativeURLDifferences(wideString(L"#β"), "http://example.org/foo/bar",
     355        {"http", "", "", "example.org", 0, "/foo/bar", "", wideString(L"β"), wideString(L"http://example.org/foo/bar#β")},
     356        {"http", "", "", "example.org", 0, "/foo/bar", "", "%CE%B2", "http://example.org/foo/bar#%CE%B2"});
    333357
    334358    // FIXME: This behavior ought to be specified in the standard.
     
    352376   
    353377    // URLParser matches Chrome and the spec, but not URL::parse or Firefox.
     378    checkURLDifferences(wideString(L"http://0Xc0.0250.01"),
     379        {"http", "", "", "192.168.0.1", 0, "/", "", "", "http://192.168.0.1/"},
     380        {"http", "", "", "0xc0.0250.01", 0, "/", "", "", "http://0xc0.0250.01/"});
    354381    checkURLDifferences("http://host/path%2e.%2E",
    355382        {"http", "", "", "host", 0, "/path...", "", "", "http://host/path..."},
Note: See TracChangeset for help on using the changeset viewer.