Directory Upload: parent path can truncate first char of the correct path
authorjohnnyg@google.com <johnnyg@google.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 20 Sep 2011 23:49:19 +0000 (23:49 +0000)
committerjohnnyg@google.com <johnnyg@google.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 20 Sep 2011 23:49:19 +0000 (23:49 +0000)
https://bugs.webkit.org/show_bug.cgi?id=66695

Source/WebCore:

In some cases, if the parent path we compute ends with a separator
character like '/' or 'C:\', by adding one in an attempt to grab the
subsequent separator we actually grab a character of the real path,
which is incorrect.

Reviewed by Darin Fisher.

* html/FileInputType.cpp:
(WebCore::FileInputType::setFileList):

LayoutTests:

Add a test case for when the parent path is '/'.

Reviewed by Darin Fisher.

* fast/forms/input-file-directory-upload.html:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@95582 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/fast/forms/input-file-directory-upload.html
Source/WebCore/ChangeLog
Source/WebCore/html/FileInputType.cpp

index 3b5abed..2fa4c65 100644 (file)
@@ -1,3 +1,14 @@
+2011-09-20  John Gregg  <johnnyg@google.com>
+
+        Directory Upload: parent path can truncate first char of the correct path
+        https://bugs.webkit.org/show_bug.cgi?id=66695
+
+        Add a test case for when the parent path is '/'.
+
+        Reviewed by Darin Fisher.
+
+        * fast/forms/input-file-directory-upload.html:
+
 2011-09-20  Jochen Eisinger  <jochen@chromium.org>
 
         Invoke CachedResourceLoader::canRequest for all URLs in a redirect chain
index 0123ee4..683ded3 100644 (file)
@@ -31,6 +31,12 @@ var testFileList4 = [
     {'path': 'resources/dirupload/path1/subpath1/file1',          'expect-relpath': 'path1/subpath1/file1' },
 ];
 
+var testFileList5 = [
+    {'path': '/foo/baz',                                          'expect-relpath': 'foo/baz'},
+    {'path': '/foo/bar/baz',                                      'expect-relpath': 'foo/bar/baz'},
+    {'path': '/foo2/baz',                                         'expect-relpath': 'foo2/baz'},
+];
+
 function log(message)
 {
     document.getElementById('output').appendChild(document.createTextNode(message + "\n"));
@@ -71,7 +77,8 @@ if (window.eventSender) {
     doTest(testFileList1);
     doTest(testFileList2);
     doTest(testFileList3);
-    doTest(testFileList4, true);
+    doTest(testFileList4);
+    doTest(testFileList5, true);
 }
 </script>
 </body>
index 6468a3d..c852014 100644 (file)
@@ -1,3 +1,18 @@
+2011-09-20  John Gregg  <johnnyg@google.com>
+
+        Directory Upload: parent path can truncate first char of the correct path
+        https://bugs.webkit.org/show_bug.cgi?id=66695
+
+        In some cases, if the parent path we compute ends with a separator
+        character like '/' or 'C:\', by adding one in an attempt to grab the
+        subsequent separator we actually grab a character of the real path,
+        which is incorrect.
+
+        Reviewed by Darin Fisher.
+
+        * html/FileInputType.cpp:
+        (WebCore::FileInputType::setFileList):
+
 2011-09-20  Jochen Eisinger  <jochen@chromium.org>
 
         Invoke CachedResourceLoader::canRequest for all URLs in a redirect chain
index a999345..cc5e679 100644 (file)
@@ -241,9 +241,12 @@ void FileInputType::setFileList(const Vector<String>& paths)
         }
         rootPath = directoryName(rootPath);
         ASSERT(rootPath.length());
+        int rootLength = rootPath.length();
+        if (rootPath[rootLength - 1] != '\\' && rootPath[rootLength - 1] != '/')
+            rootLength += 1;
         for (size_t i = 0; i < size; i++) {
             // Normalize backslashes to slashes before exposing the relative path to script.
-            String relativePath = paths[i].substring(1 + rootPath.length()).replace('\\', '/');
+            String relativePath = paths[i].substring(rootLength).replace('\\', '/');
             m_fileList->append(File::createWithRelativePath(paths[i], relativePath));
         }
         return;