Changeset 213469 in webkit


Ignore:
Timestamp:
Mar 6, 2017, 2:55:33 PM (8 years ago)
Author:
achristensen@apple.com
Message:

Fix URLs relative to file URLs with paths beginning with Windows drive letters
https://bugs.webkit.org/show_bug.cgi?id=169178

Reviewed by Tim Horton.

LayoutTests/imported/w3c:

  • web-platform-tests/url/a-element-expected.txt:
  • web-platform-tests/url/a-element-xhtml-expected.txt:
  • web-platform-tests/url/url-constructor-expected.txt:

Source/WebCore:

Windows drives in file URLs can begin with windows drive letters, such as file:///C:/
which should not be removed when making other URLs relative to them.
See https://url.spec.whatwg.org/#file-slash-state

Covered by new API tests and newly passing web-platform-tests.

  • platform/URLParser.cpp:

(WebCore::URLParser::copyBaseWindowsDriveLetter):
(WebCore::URLParser::copyASCIIStringUntil):
(WebCore::URLParser::parse):

  • platform/URLParser.h:

Tools:

  • TestWebKitAPI/Tests/WebCore/URLParser.cpp:

(TestWebKitAPI::TEST_F):

LayoutTests:

  • fast/url/relative-win-expected.txt:

Some tests pass now. localhost should indeed be removed according to the latest spec.

Location:
trunk
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r213466 r213469  
     12017-03-06  Alex Christensen  <achristensen@webkit.org>
     2
     3        Fix URLs relative to file URLs with paths beginning with Windows drive letters
     4        https://bugs.webkit.org/show_bug.cgi?id=169178
     5
     6        Reviewed by Tim Horton.
     7
     8        * fast/url/relative-win-expected.txt:
     9        Some tests pass now.  localhost should indeed be removed according to the latest spec.
     10
    1112017-03-06  Simon Fraser  <simon.fraser@apple.com>
    212
  • trunk/LayoutTests/fast/url/relative-win-expected.txt

    r212953 r213469  
    77PASS canonicalize('bar') is 'file:///C:/bar'
    88PASS canonicalize('../../../bar.html') is 'file:///C:/bar.html'
    9 FAIL canonicalize('/../bar.html') should be file:///C:/bar.html. Was file:///bar.html.
     9PASS canonicalize('/../bar.html') is 'file:///C:/bar.html'
    1010FAIL canonicalize('\\\\another\\path') should be . Was http://another/path.
    1111FAIL canonicalize('//c:/foo') should be file:///C:/foo. Was file:///c:/foo.
     
    1515FAIL canonicalize('c:\\foo') should be . Was c:\foo.
    1616FAIL canonicalize('/z:/bar') should be file:///Z:/bar. Was file:///z:/bar.
    17 FAIL canonicalize('/bar') should be file:///C:/bar. Was file:///bar.
    18 FAIL canonicalize('/bar') should be file://localhost/C:/bar. Was file:///bar.
    19 FAIL canonicalize('/bar') should be file:///C:/bar. Was file:///bar.
     17PASS canonicalize('/bar') is 'file:///C:/bar'
     18FAIL canonicalize('/bar') should be file://localhost/C:/bar. Was file:///C:/bar.
     19PASS canonicalize('/bar') is 'file:///C:/bar'
    2020PASS canonicalize('//somehost/path') is 'file://somehost/path'
    2121FAIL canonicalize('/\\//somehost/path') should be file://somehost/path. Was file:////somehost/path.
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r213457 r213469  
     12017-03-06  Alex Christensen  <achristensen@webkit.org>
     2
     3        Fix URLs relative to file URLs with paths beginning with Windows drive letters
     4        https://bugs.webkit.org/show_bug.cgi?id=169178
     5
     6        Reviewed by Tim Horton.
     7
     8        * web-platform-tests/url/a-element-expected.txt:
     9        * web-platform-tests/url/a-element-xhtml-expected.txt:
     10        * web-platform-tests/url/url-constructor-expected.txt:
     11
    1122017-03-06  Manuel Rego Casasnovas  <rego@igalia.com>
    213
  • trunk/LayoutTests/imported/w3c/web-platform-tests/url/a-element-expected.txt

    r212977 r213469  
    386386PASS Parsing: <..> against <file:///C:/>
    387387PASS Parsing: <..> against <file:///>
    388 FAIL Parsing: </> against <file:///C:/a/b> assert_equals: href expected "file:///C:/" but got "file:///"
     388PASS Parsing: </> against <file:///C:/a/b>
    389389FAIL Parsing: <//d:> against <file:///C:/a/b> assert_equals: href expected "file:///d:" but got "file://d/"
    390390PASS Parsing: <//d:/..> against <file:///C:/a/b>
  • trunk/LayoutTests/imported/w3c/web-platform-tests/url/a-element-xhtml-expected.txt

    r212977 r213469  
    386386PASS Parsing: <..> against <file:///C:/>
    387387PASS Parsing: <..> against <file:///>
    388 FAIL Parsing: </> against <file:///C:/a/b> assert_equals: href expected "file:///C:/" but got "file:///"
     388PASS Parsing: </> against <file:///C:/a/b>
    389389FAIL Parsing: <//d:> against <file:///C:/a/b> assert_equals: href expected "file:///d:" but got "file://d/"
    390390PASS Parsing: <//d:/..> against <file:///C:/a/b>
  • trunk/LayoutTests/imported/w3c/web-platform-tests/url/url-constructor-expected.txt

    r212977 r213469  
    394394PASS Parsing: <..> against <file:///C:/>
    395395PASS Parsing: <..> against <file:///>
    396 FAIL Parsing: </> against <file:///C:/a/b> assert_equals: href expected "file:///C:/" but got "file:///"
     396PASS Parsing: </> against <file:///C:/a/b>
    397397FAIL Parsing: <//d:> against <file:///C:/a/b> assert_equals: href expected "file:///d:" but got "file://d/"
    398398PASS Parsing: <//d:/..> against <file:///C:/a/b>
  • trunk/Source/WebCore/ChangeLog

    r213466 r213469  
     12017-03-06  Alex Christensen  <achristensen@webkit.org>
     2
     3        Fix URLs relative to file URLs with paths beginning with Windows drive letters
     4        https://bugs.webkit.org/show_bug.cgi?id=169178
     5
     6        Reviewed by Tim Horton.
     7
     8        Windows drives in file URLs can begin with windows drive letters, such as file:///C:/
     9        which should not be removed when making other URLs relative to them.
     10        See https://url.spec.whatwg.org/#file-slash-state
     11
     12        Covered by new API tests and newly passing web-platform-tests.
     13
     14        * platform/URLParser.cpp:
     15        (WebCore::URLParser::copyBaseWindowsDriveLetter):
     16        (WebCore::URLParser::copyASCIIStringUntil):
     17        (WebCore::URLParser::parse):
     18        * platform/URLParser.h:
     19
    1202017-03-06  Simon Fraser  <simon.fraser@apple.com>
    221
  • trunk/Source/WebCore/platform/URLParser.cpp

    r213384 r213469  
    488488}
    489489
     490bool URLParser::copyBaseWindowsDriveLetter(const URL& base)
     491{
     492    if (base.protocolIs("file")) {
     493        RELEASE_ASSERT(base.m_portEnd < base.m_string.length());
     494        if (base.m_string.is8Bit()) {
     495            const LChar* begin = base.m_string.characters8();
     496            CodePointIterator<LChar> c(begin + base.m_portEnd + 1, begin + base.m_string.length());
     497            if (isWindowsDriveLetter(c)) {
     498                appendWindowsDriveLetter(c);
     499                return true;
     500            }
     501        } else {
     502            const UChar* begin = base.m_string.characters16();
     503            CodePointIterator<UChar> c(begin + base.m_portEnd + 1, begin + base.m_string.length());
     504            if (isWindowsDriveLetter(c)) {
     505                appendWindowsDriveLetter(c);
     506                return true;
     507            }
     508        }
     509    }
     510    return false;
     511}
     512
    490513template<typename CharacterType>
    491514bool URLParser::shouldCopyFileURL(CodePointIterator<CharacterType> iterator)
     
    815838        return;
    816839    ASSERT(m_asciiBuffer.isEmpty());
    817     if (string.is8Bit()) {
     840    if (string.is8Bit())
    818841        appendToASCIIBuffer(string.characters8(), length);
    819     } else {
     842    else {
    820843        const UChar* characters = string.characters16();
    821844        for (size_t i = 0; i < length; ++i) {
     
    16031626                break;
    16041627            }
    1605             if (base.isValid() && base.protocolIs("file")) {
    1606                 // FIXME: This String copy is unnecessary.
    1607                 String basePath = base.path();
    1608                 if (basePath.length() >= 2) {
    1609                     bool windowsQuirk = basePath.is8Bit()
    1610                         ? isWindowsDriveLetter(CodePointIterator<LChar>(basePath.characters8(), basePath.characters8() + basePath.length()))
    1611                         : isWindowsDriveLetter(CodePointIterator<UChar>(basePath.characters16(), basePath.characters16() + basePath.length()));
    1612                     if (windowsQuirk) {
    1613                         appendToASCIIBuffer(basePath[0]);
    1614                         appendToASCIIBuffer(basePath[1]);
    1615                     }
    1616                 }
    1617             }
    16181628            syntaxViolation(c);
    16191629            appendToASCIIBuffer("//", 2);
     
    16231633            m_url.m_hostEnd = m_url.m_userStart;
    16241634            m_url.m_portEnd = m_url.m_userStart;
    1625             m_url.m_pathAfterLastSlash = m_url.m_userStart + 1;
    1626             if (isWindowsDriveLetter(c))
     1635            if (isWindowsDriveLetter(c)) {
    16271636                appendWindowsDriveLetter(c);
     1637                m_url.m_pathAfterLastSlash = m_url.m_userStart + 1;
     1638            } else if (copyBaseWindowsDriveLetter(base)) {
     1639                appendToASCIIBuffer('/');
     1640                m_url.m_pathAfterLastSlash = m_url.m_userStart + 4;
     1641            } else
     1642                m_url.m_pathAfterLastSlash = m_url.m_userStart + 1;
    16281643            state = State::Path;
    16291644            break;
     
    19321947        m_url.m_hostEnd = m_url.m_userStart;
    19331948        m_url.m_portEnd = m_url.m_userStart;
    1934         m_url.m_pathAfterLastSlash = m_url.m_userStart + 1;
     1949        if (copyBaseWindowsDriveLetter(base)) {
     1950            appendToASCIIBuffer('/');
     1951            m_url.m_pathAfterLastSlash = m_url.m_userStart + 4;
     1952        } else
     1953            m_url.m_pathAfterLastSlash = m_url.m_userStart + 1;
    19351954        m_url.m_pathEnd = m_url.m_pathAfterLastSlash;
    19361955        m_url.m_queryEnd = m_url.m_pathAfterLastSlash;
  • trunk/Source/WebCore/platform/URLParser.h

    r212953 r213469  
    105105    template<typename CharacterType> void encodeQuery(const Vector<UChar>& source, const TextEncoding&, CodePointIterator<CharacterType>);
    106106    void copyASCIIStringUntil(const String&, size_t length);
     107    bool copyBaseWindowsDriveLetter(const URL&);
    107108    StringView parsedDataView(size_t start, size_t length);
    108109    UChar parsedDataView(size_t position);
  • trunk/Tools/ChangeLog

    r213464 r213469  
     12017-03-06  Alex Christensen  <achristensen@webkit.org>
     2
     3        Fix URLs relative to file URLs with paths beginning with Windows drive letters
     4        https://bugs.webkit.org/show_bug.cgi?id=169178
     5
     6        Reviewed by Tim Horton.
     7
     8        * TestWebKitAPI/Tests/WebCore/URLParser.cpp:
     9        (TestWebKitAPI::TEST_F):
     10
    1112017-03-06  Myles C. Maxfield  <mmaxfield@apple.com>
    212
  • trunk/Tools/TestWebKitAPI/Tests/WebCore/URLParser.cpp

    r213384 r213469  
    581581    checkRelativeURL("http://something#", "file:////var//containers//stuff/", {"http", "", "", "something", 0, "/", "", "", "http://something/#"}, TestTabs::No);
    582582    checkRelativeURL("file:", "file:///path?query#fragment", {"file", "", "", "", 0, "/path", "query", "", "file:///path?query"});
     583    checkRelativeURL("/", "file:///C:/a/b", {"file", "", "", "", 0, "/C:/", "", "", "file:///C:/"});
     584    checkRelativeURL("/abc", "file:///C:/a/b", {"file", "", "", "", 0, "/C:/abc", "", "", "file:///C:/abc"});
     585    checkRelativeURL("/abc", "file:///C:", {"file", "", "", "", 0, "/C:/abc", "", "", "file:///C:/abc"});
     586    checkRelativeURL("/abc", "file:///", {"file", "", "", "", 0, "/abc", "", "", "file:///abc"});
    583587
    584588    // The checking of slashes in SpecialAuthoritySlashes needed to get this to pass contradicts what is in the spec,
Note: See TracChangeset for help on using the changeset viewer.