Changeset 223135 in webkit


Ignore:
Timestamp:
Oct 10, 2017 11:42:34 AM (7 years ago)
Author:
Chris Dumez
Message:

Entries API should recognize path starting with 2 slashes as valid absolute path
https://bugs.webkit.org/show_bug.cgi?id=178135

Reviewed by Ryosuke Niwa.

Source/WebCore:

Entries API should recognize paths starting with 2 slashes as valid absolute paths to match Chrome's behavior.
See https://github.com/WICG/entries-api/commit/990454758005a6039655835503d551015e346d9d

This was causing us to fail some manual web-platform-tests.

No new tests, updated existing tests.

  • Modules/entriesapi/DOMFileSystem.cpp:

(WebCore::isValidPathSegment):
(WebCore::isZeroOrMorePathSegmentsSeparatedBySlashes):
(WebCore::isValidRelativeVirtualPath):
(WebCore::isValidVirtualPath):

LayoutTests:

Add layout test coverage.

  • editing/pasteboard/entries-api/datatransfer-items-drop-getDirectory-expected.txt:
  • editing/pasteboard/entries-api/datatransfer-items-drop-getDirectory.html:
  • editing/pasteboard/entries-api/datatransfer-items-drop-getFile-expected.txt:
  • editing/pasteboard/entries-api/datatransfer-items-drop-getFile.html:
Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r223134 r223135  
     12017-10-10  Chris Dumez  <cdumez@apple.com>
     2
     3        Entries API should recognize path starting with 2 slashes as valid absolute path
     4        https://bugs.webkit.org/show_bug.cgi?id=178135
     5
     6        Reviewed by Ryosuke Niwa.
     7
     8        Add layout test coverage.
     9
     10        * editing/pasteboard/entries-api/datatransfer-items-drop-getDirectory-expected.txt:
     11        * editing/pasteboard/entries-api/datatransfer-items-drop-getDirectory.html:
     12        * editing/pasteboard/entries-api/datatransfer-items-drop-getFile-expected.txt:
     13        * editing/pasteboard/entries-api/datatransfer-items-drop-getFile.html:
     14
    1152017-10-10  Matt Lewis  <jlewis3@apple.com>
    216
  • trunk/LayoutTests/editing/pasteboard/entries-api/datatransfer-items-drop-getDirectory-expected.txt

    r223118 r223135  
    6363PASS testFilesEntry.name is "testFiles"
    6464PASS testFilesEntry.fullPath is "/testFiles"
     65* Edge case: calling getDirectory() with path starting with 2 slashes
     66PASS testFilesEntry.isFile is false
     67PASS testFilesEntry.isDirectory is true
     68PASS testFilesEntry.name is "subfolder1"
     69PASS testFilesEntry.fullPath is "/testFiles/subfolder1"
     70* Edge case: calling getDirectory() with path starting with 2 slashes and containing 2 following slashes
     71PASS testFilesEntry.isFile is false
     72PASS testFilesEntry.isDirectory is true
     73PASS testFilesEntry.name is "subfolder1"
     74PASS testFilesEntry.fullPath is "/testFiles/subfolder1"
    6575PASS successfullyParsed is true
    6676
  • trunk/LayoutTests/editing/pasteboard/entries-api/datatransfer-items-drop-getDirectory.html

    r223118 r223135  
    201201    }, e => {
    202202        testFailed("getDirectory('.') should succeed");
     203    });
     204}
     205
     206function test17() {
     207    debug("* Edge case: calling getDirectory() with path starting with 2 slashes");
     208    return getDirectoryAsPromise(directoryEntry, '//testFiles/subfolder1', {}).then(entry => {
     209        testFilesEntry = entry;
     210        shouldBeFalse("testFilesEntry.isFile");
     211        shouldBeTrue("testFilesEntry.isDirectory");
     212        shouldBeEqualToString("testFilesEntry.name", "subfolder1");
     213        shouldBeEqualToString("testFilesEntry.fullPath", "/testFiles/subfolder1");
     214    }, e => {
     215        testFailed("getDirectory('//testFiles/subfolder1') should succeed");
     216    });
     217}
     218
     219function test18() {
     220    debug("* Edge case: calling getDirectory() with path starting with 2 slashes and containing 2 following slashes");
     221    return getDirectoryAsPromise(directoryEntry, '//testFiles//subfolder1', {}).then(entry => {
     222        testFilesEntry = entry;
     223        shouldBeFalse("testFilesEntry.isFile");
     224        shouldBeTrue("testFilesEntry.isDirectory");
     225        shouldBeEqualToString("testFilesEntry.name", "subfolder1");
     226        shouldBeEqualToString("testFilesEntry.fullPath", "/testFiles/subfolder1");
     227    }, e => {
     228        testFailed("getDirectory('//testFiles//subfolder1') should succeed");
    203229    });
    204230}
     
    228254    .then(test15)
    229255    .then(test16)
     256    .then(test17)
     257    .then(test18)
    230258    .then(finishJSTest);
    231259};
  • trunk/LayoutTests/editing/pasteboard/entries-api/datatransfer-items-drop-getFile-expected.txt

    r221556 r223135  
    4343* Error case: calling getFile() with empty path
    4444PASS ex.name is "TypeMismatchError"
     45* Edge case: calling getFile() with absolute path starting with 2 slashes
     46PASS file1Entry.name is "file1.txt"
     47PASS file1Entry.fullPath is "/testFiles/file1.txt"
     48PASS file1Entry.isFile is true
     49* Edge case: calling getFile() with absolute path starting with 2 slashes and containing 2 following slashes
     50PASS file1Entry.name is "file1.txt"
     51PASS file1Entry.fullPath is "/testFiles/file1.txt"
     52PASS file1Entry.isFile is true
    4553PASS successfullyParsed is true
    4654
  • trunk/LayoutTests/editing/pasteboard/entries-api/datatransfer-items-drop-getFile.html

    r221556 r223135  
    157157        ex = e;
    158158        shouldBeEqualToString("ex.name", "TypeMismatchError");
     159    });
     160}
     161
     162function test14() {
     163    debug("* Edge case: calling getFile() with absolute path starting with 2 slashes");
     164    return getFileAsPromise(directoryEntry, "//testFiles/file1.txt", {}).then(entry => {
     165        file1Entry = entry;
     166        shouldBeEqualToString("file1Entry.name", "file1.txt");
     167        shouldBeEqualToString("file1Entry.fullPath", "/testFiles/file1.txt");
     168        shouldBeTrue("file1Entry.isFile");
     169    }, e => {
     170        testFailed("getFile('//testFiles/file1.txt') should succeed");
     171    });
     172}
     173
     174function test15() {
     175    debug("* Edge case: calling getFile() with absolute path starting with 2 slashes and containing 2 following slashes");
     176    return getFileAsPromise(directoryEntry, "//testFiles//file1.txt", {}).then(entry => {
     177        file1Entry = entry;
     178        shouldBeEqualToString("file1Entry.name", "file1.txt");
     179        shouldBeEqualToString("file1Entry.fullPath", "/testFiles/file1.txt");
     180        shouldBeTrue("file1Entry.isFile");
     181    }, e => {
     182        testFailed("getFile('//testFiles//file1.txt') should succeed");
    159183    });
    160184}
     
    181205    .then(test12)
    182206    .then(test13)
     207    .then(test14)
     208    .then(test15)
    183209    .then(finishJSTest);
    184210};
  • trunk/Source/WebCore/ChangeLog

    r223134 r223135  
     12017-10-10  Chris Dumez  <cdumez@apple.com>
     2
     3        Entries API should recognize path starting with 2 slashes as valid absolute path
     4        https://bugs.webkit.org/show_bug.cgi?id=178135
     5
     6        Reviewed by Ryosuke Niwa.
     7
     8        Entries API should recognize paths starting with 2 slashes as valid absolute paths to match Chrome's behavior.
     9        See https://github.com/WICG/entries-api/commit/990454758005a6039655835503d551015e346d9d
     10
     11        This was causing us to fail some manual web-platform-tests.
     12
     13        No new tests, updated existing tests.
     14
     15        * Modules/entriesapi/DOMFileSystem.cpp:
     16        (WebCore::isValidPathSegment):
     17        (WebCore::isZeroOrMorePathSegmentsSeparatedBySlashes):
     18        (WebCore::isValidRelativeVirtualPath):
     19        (WebCore::isValidVirtualPath):
     20
    1212017-10-10  Matt Lewis  <jlewis3@apple.com>
    222
  • trunk/Source/WebCore/Modules/entriesapi/DOMFileSystem.cpp

    r223118 r223135  
    9797static bool isValidPathSegment(StringView segment)
    9898{
    99     ASSERT(!segment.isEmpty());
    100     if (segment == "." || segment == "..")
     99    if (segment.isEmpty() || segment == "." || segment == "..")
    101100        return true;
    102101
     
    108107}
    109108
    110 // https://wicg.github.io/entries-api/#relative-path
    111 static bool isValidRelativeVirtualPath(StringView virtualPath)
    112 {
    113     if (virtualPath.isEmpty())
    114         return false;
    115 
    116     if (virtualPath[0] == '/')
    117         return false;
    118 
    119     auto segments = virtualPath.split('/');
     109static bool isZeroOrMorePathSegmentsSeparatedBySlashes(StringView string)
     110{
     111    auto segments = string.split('/');
    120112    for (auto segment : segments) {
    121113        if (!isValidPathSegment(segment))
     
    125117}
    126118
     119// https://wicg.github.io/entries-api/#relative-path
     120static bool isValidRelativeVirtualPath(StringView virtualPath)
     121{
     122    if (virtualPath.isEmpty())
     123        return false;
     124
     125    if (virtualPath[0] == '/')
     126        return false;
     127
     128    return isZeroOrMorePathSegmentsSeparatedBySlashes(virtualPath);
     129}
     130
    127131// https://wicg.github.io/entries-api/#valid-path
    128132static bool isValidVirtualPath(StringView virtualPath)
     
    130134    if (virtualPath.isEmpty())
    131135        return true;
    132     if (virtualPath[0] == '/')
    133         return virtualPath.length() == 1 || isValidRelativeVirtualPath(virtualPath.substring(1));
     136    if (virtualPath[0] == '/') {
     137        // An absolute path is a string consisting of '/' (U+002F SOLIDUS) followed by one or more path segments joined by '/' (U+002F SOLIDUS).
     138        return isZeroOrMorePathSegmentsSeparatedBySlashes(virtualPath.substring(1));
     139    }
    134140    return isValidRelativeVirtualPath(virtualPath);
    135141}
Note: See TracChangeset for help on using the changeset viewer.