Changeset 93750 in webkit


Ignore:
Timestamp:
Aug 24, 2011 5:59:51 PM (13 years ago)
Author:
ericu@chromium.org
Message:

Reviewed by Adam Barth.

[filesystem/Chromium] Filesystem paths need proper URL escaping
https://bugs.webkit.org/show_bug.cgi?id=62811

Fix http://code.google.com/p/chromium/issues/detail?id=78860 by making
KURLChromium.cpp's escaping code actually work.

Source/WebCore:

Make encodeWithURLEscapeSequences call into googleurl to do proper
escaping. Tested in WebKit/chromium/tests/KURLTest.cpp.

  • platform/KURLGoogle.cpp:

(WebCore::encodeWithURLEscapeSequences):

Source/WebKit/chromium:

Here I added the needed calls to encodeWithURLEscapeSequences.

  • src/AsyncFileSystemChromium.cpp:

(WebCore::AsyncFileSystemChromium::virtualPathToFileSystemURL):

  • src/WorkerAsyncFileSystemChromium.cpp:

(WebCore::WorkerAsyncFileSystemChromium::virtualPathToFileSystemURL):

Here I updated the test to reflect the new functionality in
encodeWithURLEscapeSequences.

  • tests/KURLTest.cpp:
Location:
trunk/Source
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r93749 r93750  
     12011-08-24  Eric Uhrhane  <ericu@chromium.org>
     2
     3        Reviewed by Adam Barth.
     4
     5        [filesystem/Chromium] Filesystem paths need proper URL escaping
     6        https://bugs.webkit.org/show_bug.cgi?id=62811
     7
     8        Fix http://code.google.com/p/chromium/issues/detail?id=78860 by making
     9        KURLChromium.cpp's escaping code actually work.
     10
     11        Make encodeWithURLEscapeSequences call into googleurl to do proper
     12        escaping.  Tested in WebKit/chromium/tests/KURLTest.cpp.
     13        * platform/KURLGoogle.cpp:
     14        (WebCore::encodeWithURLEscapeSequences):
     15
    1162011-08-24  Chris Palmer  <palmer@google.com>
    217
  • trunk/Source/WebCore/page/SecurityOrigin.cpp

    r92068 r93750  
    6666}
    6767
    68 
    6968SecurityOrigin::SecurityOrigin(const KURL& url, SandboxFlags sandboxFlags)
    7069    : m_sandboxFlags(sandboxFlags)
     
    9291#endif
    9392    if (isBlobOrFileSystemProtocol) {
    94         KURL originURL(ParsedURLString, url.path());
     93        KURL originURL(ParsedURLString, decodeURLEscapeSequences(url.path()));
    9594        if (originURL.isValid()) {
    9695            m_protocol = originURL.protocol().lower();
  • trunk/Source/WebCore/platform/KURLGoogle.cpp

    r89178 r93750  
    835835}
    836836
    837 // This is called to escape a URL string. It is only used externally when
    838 // constructing mailto: links to set the query section. Since our query setter
    839 // will automatically do the correct escaping, this function does not have to
    840 // do any work.
    841 //
    842 // There is a possibility that a future caller may use this function in other
    843 // ways, and may expect to get a valid URL string. The dangerous thing we want
    844 // to protect against here is accidentally getting '\0' characters in a string
    845 // that is not supposed to have them. Therefore, we escape these characters.
    846837String encodeWithURLEscapeSequences(const String& notEncodedString)
    847838{
     
    852843    const char* input = utf8.data();
    853844    int inputLength = utf8.length();
    854 
    855     Vector<char, 2048> buffer;
    856     for (int i = 0; i < inputLength; i++) {
    857         if (!input[i])
    858             buffer.append("%00", 3);
    859         else
    860             buffer.append(input[i]);
    861     }
    862     return String(buffer.data(), buffer.size());
     845    url_canon::RawCanonOutputT<char> buffer;
     846    if (buffer.length() < inputLength * 3)
     847        buffer.Resize(inputLength * 3);
     848
     849    url_util::EncodeURIComponent(input, inputLength, &buffer);
     850    return String(buffer.data(), buffer.length());
    863851}
    864852
  • trunk/Source/WebKit/chromium/ChangeLog

    r93747 r93750  
     12011-08-24  Eric Uhrhane  <ericu@chromium.org>
     2
     3        Reviewed by Adam Barth.
     4
     5        [filesystem/Chromium] Filesystem paths need proper URL escaping
     6        https://bugs.webkit.org/show_bug.cgi?id=62811
     7
     8        Fix http://code.google.com/p/chromium/issues/detail?id=78860 by making
     9        KURLChromium.cpp's escaping code actually work.
     10
     11        Here I added the needed calls to encodeWithURLEscapeSequences.
     12        * src/AsyncFileSystemChromium.cpp:
     13        (WebCore::AsyncFileSystemChromium::virtualPathToFileSystemURL):
     14        * src/WorkerAsyncFileSystemChromium.cpp:
     15        (WebCore::WorkerAsyncFileSystemChromium::virtualPathToFileSystemURL):
     16
     17        Here I updated the test to reflect the new functionality in
     18        encodeWithURLEscapeSequences.
     19        * tests/KURLTest.cpp:
     20
    1212011-08-24  Ilya Sherman  <isherman@chromium.org>
    222
  • trunk/Source/WebKit/chromium/src/AsyncFileSystemChromium.cpp

    r89178 r93750  
    178178    KURL url = m_filesystemRootURL;
    179179    // Remove the extra leading slash.
    180     url.setPath(url.path() + virtualPath.substring(1));
     180    url.setPath(url.path() + encodeWithURLEscapeSequences(virtualPath.substring(1)));
    181181    return url;
    182182}
  • trunk/Source/WebKit/chromium/src/WorkerAsyncFileSystemChromium.cpp

    r89178 r93750  
    228228    KURL url = m_filesystemRootURL;
    229229    // Remove the extra leading slash.
    230     url.setPath(url.path() + virtualPath.substring(1));
     230    url.setPath(url.path() + encodeWithURLEscapeSequences(virtualPath.substring(1)));
    231231    return url;
    232232}
  • trunk/Source/WebKit/chromium/tests/KURLTest.cpp

    r89178 r93750  
    307307TEST(KURLTest, Encode)
    308308{
     309    struct EncodeCase {
     310        const char* input;
     311        const char* output;
     312    } encode_cases[] = {
     313        {"hello, world", "hello%2C%20world"},
     314        {"\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F",
     315          "%01%02%03%04%05%06%07%08%09%0A%0B%0C%0D%0E%0F"},
     316        {"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F",
     317          "%10%11%12%13%14%15%16%17%18%19%1A%1B%1C%1D%1E%1F"},
     318        {" !\"#$%&'()*+,-./",
     319          "%20!%22%23%24%25%26'()*%2B%2C-.%2F"},
     320        {"0123456789:;<=>?",
     321          "0123456789%3A%3B%3C%3D%3E%3F"},
     322        {"@ABCDEFGHIJKLMNO",
     323          "%40ABCDEFGHIJKLMNO"},
     324        {"PQRSTUVWXYZ[\\]^_",
     325          "PQRSTUVWXYZ%5B%5C%5D%5E_"},
     326        {"`abcdefghijklmno",
     327          "%60abcdefghijklmno"},
     328        {"pqrstuvwxyz{|}~\x7f",
     329          "pqrstuvwxyz%7B%7C%7D~%7F"},
     330    };
     331
     332    for (size_t i = 0; i < ARRAYSIZE_UNSAFE(encode_cases); i++) {
     333        WTF::String input(encode_cases[i].input);
     334        WTF::String expectedOutput(encode_cases[i].output);
     335        WTF::String output = WebCore::encodeWithURLEscapeSequences(input);
     336        EXPECT_EQ(expectedOutput, output);
     337    }
     338
     339    // Our encode escapes NULLs for safety, so we need to check that too.
     340    WTF::String input("\x00\x01", 2);
     341    WTF::String reference("%00%01");
     342
     343    WTF::String output = WebCore::encodeWithURLEscapeSequences(input);
     344    EXPECT_EQ(reference, output);
     345
    309346    // Also test that it gets converted to UTF-8 properly.
    310347    char16 wideInputHelper[3] = { 0x4f60, 0x597d, 0 };
    311348    WTF::String wideInput(
    312349        reinterpret_cast<const ::UChar*>(wideInputHelper), 2);
    313     WTF::String wideReference("\xe4\xbd\xa0\xe5\xa5\xbd", 6);
     350    WTF::String wideReference("%E4%BD%A0%E5%A5%BD");
    314351    WTF::String wideOutput =
    315352        WebCore::encodeWithURLEscapeSequences(wideInput);
    316353    EXPECT_EQ(wideReference, wideOutput);
    317 
    318     // Our encode only escapes NULLs for safety (see the implementation for
    319     // more), so we only bother to test a few cases.
    320     WTF::String input(
    321         "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f", 16);
    322     WTF::String reference(
    323         "%00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f", 18);
    324     WTF::String output = WebCore::encodeWithURLEscapeSequences(input);
    325     EXPECT_EQ(reference, output);
    326354}
    327355
Note: See TracChangeset for help on using the changeset viewer.