Changeset 206157 in webkit


Ignore:
Timestamp:
Sep 20, 2016 11:27:37 AM (8 years ago)
Author:
achristensen@apple.com
Message:

Fix Windows file URL quirks in URLParser
https://bugs.webkit.org/show_bug.cgi?id=162303

Reviewed by Tim Horton.

Source/WebCore:

Windows file urls allow c:\ and c|\ to have the same meaning, but when serialized they should both be c:/.
This is now standardized to allow cross-platform uniform behavior of URLs.

Covered by new API tests and progress on web platform tests when URLParser is enabled.

  • platform/URLParser.cpp:

(WebCore::incrementIteratorSkippingTabAndNewLine):
(WebCore::isWindowsDriveLetter):
(WebCore::checkWindowsDriveLetter):
(WebCore::shouldCopyFileURL):
(WebCore::URLParser::parseSerializedURL):
(WebCore::URLParser::parse):

Tools:

  • TestWebKitAPI/Tests/WebCore/URLParser.cpp:

(TestWebKitAPI::TEST_F):

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r206156 r206157  
     12016-09-20  Alex Christensen  <achristensen@webkit.org>
     2
     3        Fix Windows file URL quirks in URLParser
     4        https://bugs.webkit.org/show_bug.cgi?id=162303
     5
     6        Reviewed by Tim Horton.
     7
     8        Windows file urls allow c:\ and c|\ to have the same meaning, but when serialized they should both be c:/.
     9        This is now standardized to allow cross-platform uniform behavior of URLs.
     10
     11        Covered by new API tests and progress on web platform tests when URLParser is enabled.
     12
     13        * platform/URLParser.cpp:
     14        (WebCore::incrementIteratorSkippingTabAndNewLine):
     15        (WebCore::isWindowsDriveLetter):
     16        (WebCore::checkWindowsDriveLetter):
     17        (WebCore::shouldCopyFileURL):
     18        (WebCore::URLParser::parseSerializedURL):
     19        (WebCore::URLParser::parse):
     20
    1212016-09-20  Said Abou-Hallawa  <sabouhallawa@apple.com>
    222
  • trunk/Source/WebCore/platform/URLParser.cpp

    r206126 r206157  
    394394template<typename CharacterType> inline static bool isSlashQuestionOrHash(CharacterType character) { return character <= '\\' && characterClassTable[character] & SlashQuestionOrHash; }
    395395static bool shouldPercentEncodeQueryByte(uint8_t byte) { return characterClassTable[byte] & QueryPercent; }
    396    
    397 template<typename CharacterType>
     396
     397template<bool serialized, typename CharacterType>
     398void incrementIteratorSkippingTabAndNewLine(CodePointIterator<CharacterType>& iterator)
     399{
     400    ++iterator;
     401    while (!serialized && !iterator.atEnd() && isTabOrNewline(*iterator))
     402        ++iterator;
     403}
     404
     405template<bool serialized, typename CharacterType>
    398406inline static bool isWindowsDriveLetter(CodePointIterator<CharacterType> iterator)
    399407{
    400408    if (iterator.atEnd() || !isASCIIAlpha(*iterator))
    401409        return false;
    402     ++iterator;
     410    incrementIteratorSkippingTabAndNewLine<serialized>(iterator);
    403411    if (iterator.atEnd())
    404412        return false;
     
    413421}
    414422
    415 template<typename CharacterType>
     423template<bool serialized, typename CharacterType>
     424inline static void checkWindowsDriveLetter(CodePointIterator<CharacterType>& iterator, Vector<LChar>& asciiBuffer)
     425{
     426    if (isWindowsDriveLetter<serialized>(iterator)) {
     427        asciiBuffer.reserveCapacity(asciiBuffer.size() + 2);
     428        asciiBuffer.uncheckedAppend(*iterator);
     429        incrementIteratorSkippingTabAndNewLine<serialized>(iterator);
     430        ASSERT(!iterator.atEnd());
     431        ASSERT(*iterator == ':' || *iterator == '|');
     432        asciiBuffer.uncheckedAppend(':');
     433        incrementIteratorSkippingTabAndNewLine<serialized>(iterator);
     434    }
     435}
     436
     437template<bool serialized, typename CharacterType>
    416438inline static bool shouldCopyFileURL(CodePointIterator<CharacterType> iterator)
    417439{
    418     if (isWindowsDriveLetter(iterator))
     440    if (!isWindowsDriveLetter<serialized>(iterator))
    419441        return true;
    420442    if (iterator.atEnd())
    421443        return false;
    422     ++iterator;
     444    incrementIteratorSkippingTabAndNewLine<serialized>(iterator);
    423445    if (iterator.atEnd())
    424446        return true;
    425     ++iterator;
     447    incrementIteratorSkippingTabAndNewLine<serialized>(iterator);
    426448    if (iterator.atEnd())
    427449        return true;
     
    890912        return parse<serialized>(input.characters8(), input.length(), { }, UTF8Encoding());
    891913    return parse<serialized>(input.characters16(), input.length(), { }, UTF8Encoding());
    892 }
    893 
    894 template<bool serialized, typename CharacterType>
    895 void incrementIteratorSkippingTabAndNewLine(CodePointIterator<CharacterType>& iterator)
    896 {
    897     ++iterator;
    898     while (!serialized && !iterator.atEnd() && isTabOrNewline(*iterator))
    899         ++iterator;
    900914}
    901915   
     
    12051219                break;
    12061220            default:
    1207                 if (!base.isNull() && base.protocolIs("file") && shouldCopyFileURL(c))
     1221                if (!base.isNull() && base.protocolIs("file") && shouldCopyFileURL<serialized>(c))
    12081222                    copyURLPartsUntil(base, URLPart::PathAfterLastSlash);
    12091223                else {
     
    12151229                    m_url.m_portEnd = m_url.m_userStart;
    12161230                    m_url.m_pathAfterLastSlash = m_url.m_userStart + 1;
     1231                    checkWindowsDriveLetter<serialized>(c, m_asciiBuffer);
    12171232                }
    12181233                state = State::Path;
     
    12391254                if (basePath.length() >= 2) {
    12401255                    bool windowsQuirk = basePath.is8Bit()
    1241                         ? isWindowsDriveLetter(CodePointIterator<LChar>(basePath.characters8(), basePath.characters8() + basePath.length()))
    1242                         : isWindowsDriveLetter(CodePointIterator<UChar>(basePath.characters16(), basePath.characters16() + basePath.length()));
     1256                        ? isWindowsDriveLetter<serialized>(CodePointIterator<LChar>(basePath.characters8(), basePath.characters8() + basePath.length()))
     1257                        : isWindowsDriveLetter<serialized>(CodePointIterator<UChar>(basePath.characters16(), basePath.characters16() + basePath.length()));
    12431258                    if (windowsQuirk) {
    12441259                        m_asciiBuffer.append(basePath[0]);
     
    12461261                    }
    12471262                }
    1248                 state = State::Path;
    1249                 break;
    12501263            }
    12511264            m_asciiBuffer.append("//", 2);
     
    12561269            m_url.m_portEnd = m_url.m_userStart;
    12571270            m_url.m_pathAfterLastSlash = m_url.m_userStart + 1;
     1271            checkWindowsDriveLetter<serialized>(c, m_asciiBuffer);
    12581272            state = State::Path;
    12591273            break;
  • trunk/Tools/ChangeLog

    r206154 r206157  
     12016-09-20  Alex Christensen  <achristensen@webkit.org>
     2
     3        Fix Windows file URL quirks in URLParser
     4        https://bugs.webkit.org/show_bug.cgi?id=162303
     5
     6        Reviewed by Tim Horton.
     7
     8        * TestWebKitAPI/Tests/WebCore/URLParser.cpp:
     9        (TestWebKitAPI::TEST_F):
     10
    1112016-09-20  Filip Pizlo  <fpizlo@apple.com>
    212
  • trunk/Tools/TestWebKitAPI/Tests/WebCore/URLParser.cpp

    r206126 r206157  
    527527        {"http", "", "", "123.234.0.12", 0, "/", "", "", "http://123.234.0.12/"},
    528528        {"http", "", "", "123.234.12", 0, "/", "", "", "http://123.234.12/"});
     529    checkRelativeURLDifferences("file:c:\\foo\\bar.html", "file:///tmp/mock/path",
     530        {"file", "", "", "", 0, "/c:/foo/bar.html", "", "", "file:///c:/foo/bar.html"},
     531        {"file", "", "", "", 0, "/tmp/mock/c:/foo/bar.html", "", "", "file:///tmp/mock/c:/foo/bar.html"});
     532    checkRelativeURLDifferences("  File:c|////foo\\bar.html", "file:///tmp/mock/path",
     533        {"file", "", "", "", 0, "/c:////foo/bar.html", "", "", "file:///c:////foo/bar.html"},
     534        {"file", "", "", "", 0, "/tmp/mock/c|////foo/bar.html", "", "", "file:///tmp/mock/c|////foo/bar.html"});
     535    checkRelativeURLDifferences("  Fil\t\n\te\n\t\n:\t\n\tc\t\n\t|\n\t\n/\t\n\t/\n\t\n//foo\\bar.html", "file:///tmp/mock/path",
     536        {"file", "", "", "", 0, "/c:////foo/bar.html", "", "", "file:///c:////foo/bar.html"},
     537        {"file", "", "", "", 0, "/tmp/mock/c|////foo/bar.html", "", "", "file:///tmp/mock/c|////foo/bar.html"});
     538    checkRelativeURLDifferences("C|/foo/bar", "file:///tmp/mock/path",
     539        {"file", "", "", "", 0, "/C:/foo/bar", "", "", "file:///C:/foo/bar"},
     540        {"file", "", "", "", 0, "/tmp/mock/C|/foo/bar", "", "", "file:///tmp/mock/C|/foo/bar"});
     541    checkRelativeURLDifferences("/C|/foo/bar", "file:///tmp/mock/path",
     542        {"file", "", "", "", 0, "/C:/foo/bar", "", "", "file:///C:/foo/bar"},
     543        {"file", "", "", "", 0, "/C|/foo/bar", "", "", "file:///C|/foo/bar"});
    529544}
    530545
Note: See TracChangeset for help on using the changeset viewer.