New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 124187 link

Starred by 79 users

Issue metadata

Status: Fixed
Owner:
Closed: Nov 14
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: All
Pri: 2
Type: Bug

Blocked on:
issue 869257



Sign in to add a comment

webkitdirectory input returns wrong path of selected files

Reported by martin.p...@gmail.com, Apr 19 2012

Issue description

Chrome Version       : 18.0.1025.162
OS Version: 6.1 (Windows 7, Windows Server 2008 R2)

What steps will reproduce the problem?
1. Have this folder/file structure:
folder "a" -> folder "b" -> folder "c" -> file "d.txt"

2. Use input with webkitdirectory and select folder "a"

What is the expected result?
Files property lists these files:
- name: ".", path: "a/."
- name: ".", path: "a/b/."
- name: ".", path: "a/b/c/."
- name: "d.txt", path: "a/b/c/d.txt"
I should be able to reconstruct full folder structure from the files.

What happens instead?
Files property lists these files:
- name: ".", path: "b/."
- name: ".", path: "b/c/."
- name: "d.txt", path: "b/c/d.txt"
From these files I'm not able to reconstruct full folder structure of selected folder, since there is completely missing the root folder (the selected folder "a")

If the root folder contains at least one file, all files contain correct path, but there is still missing file with name "." and path "a/."

The behaviour should be consistent across all folders in the folder structure regardless where the folder is located, so if I select empty folder, there should be one file with name "." and path "folder-name/."

UserAgentString: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.162 Safari/535.19



 

Comment 1 by tkent@chromium.org, Apr 20 2012

Cc: johnnyg@chromium.org
Labels: -Area-Undefined Area-WebKit WebKit-Forms
Project Member

Comment 2 by bugdroid1@chromium.org, Mar 10 2013

Labels: -Area-WebKit -WebKit-Forms Cr-Content Cr-Content-Forms

Comment 3 by Deleted ...@, Mar 11 2013

It only happens when selected folder does not have files in it and there is only one child folder (or first child folder name only has one character and all other child folders starts with that same character). 

I was able to develop an algorithm to identify problem and request user to enter selected folder name manually so that I can append all webkitRelativePath for files with entered folder name.

Chrome Version 25.0.1364.160 m on Windows 7 Pro and Mac OSX Lion

Please let us know when you fix this. Thanks.
Project Member

Comment 4 by bugdroid1@chromium.org, Apr 6 2013

Labels: -Cr-Content Cr-Blink
Project Member

Comment 5 by bugdroid1@chromium.org, Apr 6 2013

Labels: -Cr-Content-Forms Cr-Blink-Forms
Cc: kenjibaheux@chromium.org
Labels: tbc-p3
Status: Untriaged
Confirmed on Windows with M26 (seeing 3 files)

Comment 9 by tkent@chromium.org, May 8 2013

Labels: -OS-Windows -tbc-p3 OS-All
Status: WontFix
AFAIK, this is work-as-intended.  We omit shallower directory names as possible in order to avoid to disclose user's directory structure to web applications, but keep minimal directory names to distinguish selected files.


That seems really broken. Not being able to consistently depend on the path means that a user dragging a folder into the browser isn't guaranteed to get the structure they expected.

On top of that, the correct paths for the files dragged in can be built through more obtuse methods like iterating through each folder object and enumerating its children. It's only the path property that is unpredictable.
Hello. Just wanted to comment again and see if you would reconsider the browser behavior here. Retaining the structure of a dragged in folder is generally pretty important.

Comment 12 by Deleted ...@, Jun 25 2013

I implement a workaround using this algorithm (javascript),
var firstPath=evt.target.files[0].webkitRelativePath;
var nOfDirs=(firstPath).split("/");
/* check webkitDirectory bug */
if(((firstPath).substring((firstPath).lastIndexOf("/") + 1)==".") && (nOfDirs.length)%2==0){
	//ask user to enter selected folder name and add the folder to beginning of all file paths
}else{
	// no issues
}

This causes problem for my app where users upload a folder and expect it to keep the same folder structure. 

I'm trying to think how this protects users. I guess users might do something stupid like try to upload their root folder. Which is more likely to crash the browser than anything else. Maybe a better way to protect users is to make sharing system folders off-limits.

Comment 14 by tkent@chromium.org, Apr 24 2014

 Issue 366620  has been merged into this issue.

Comment 15 by tkent@chromium.org, Apr 24 2014

Labels: Cr-Blink-Forms-File Cr-Blink-Forms-File-Directory

Comment 16 by Deleted ...@, Nov 21 2015

Is there any chance for re-opening this issue?

I'm working on an application that involves uploading a directory structure. The directory structure carries implied meaning about the files contained within.

I saw above that this was implemented as such do to security concerns. Is this a security concern do to potential user error or something deeper?

Comment 17 by tkent@chromium.org, Apr 18 2016

Cc: tkent@chromium.org
 Issue 138589  has been merged into this issue.

Comment 18 by tkent@chromium.org, Jan 10 2017

 Issue 672283  has been merged into this issue.
Components: -Blink>Forms>File -Blink -Blink>Forms
Owner: jsb...@chromium.org
Status: Available (was: WontFix)
Now that Edge/Firefox/Safari have implemented support for webkitRelativePath... none of them followed Chrome's behavior of eliminating the common ancestors.

I added this as a spec issue https://github.com/WICG/entries-api/issues/18 since it's specified but Chrome is now "outvoted". Maybe we should fix.

It's also inconsistent with drag/drop where we do get the full directory structure. That hasn't been highlighted as a security concern.
Cc: jsb...@chromium.org
Owner: ----

Comment 21 by tkent@chromium.org, Jan 25 2018

Cc: -johnnyg@chromium.org
Labels: Hotlist-Interop Hotlist-GoodFirstBug
It seems Blink just receives a file list in the selected directory, and doesn't know the selected directory.  So it's not easy to create the interoperable webkitRelativePath.

We need to extend IPC messages for file choosers. Probably we should switch to Mojo first.

Blockedon: 869257
Labels: -Hotlist-GoodFirstBug
Summary: webkitdirectory input returns wrong path of selected files (was: Webkitdirectory input returns wrong path of selected files)
Hi all, does someone have an update on the this issue? It is currently the 5th most starred Hotlist-Interop issue. By now all engines support webkitdirectory and it's spec'd in https://wicg.github.io/entries-api/#html-forms.
Owner: tkent@chromium.org
Status: Assigned (was: Available)
I'm actively working on a blocking issue, and will fix this after it.

That's great to hear, thanks tkent@!
Awesome!

Note that the spec does define the current Chrome behavior "In addition, the webkitRelativePath property of each File is set to a relative path from the shortest common ancestor directory of all selected files to that file, including that ancestor in the path. (Therefore this may be a subdirectory of the selected directory rather than the directory itself.)" but agreed it's confusing and I'm hopeful we can change.

(We may finally have cycles on the storage/datatransfer team to help out here soon too.)
Cc: huangdarwin@chromium.org
Status: Started (was: Assigned)
Project Member

Comment 32 by bugdroid1@chromium.org, Nov 8

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/f81a5040023b4a9e865a28e097a04105fa447638

commit f81a5040023b4a9e865a28e097a04105fa447638
Author: Kent Tamura <tkent@chromium.org>
Date: Thu Nov 08 02:12:21 2018

input[type=file]: Save and restore webkitRelativePath values

Before this CL, we didn't save webkitRelativePath values on saving
a tab session, and we computed them with the longest common ancestor
directory of all files on restoring the tab session. After this CL,
we save webkitRelativePath values, and restore them without finding
the common ancestor directory.  This CL is a preparation of fixing
 crbug.com/124187 .

* FileInputType::SaveFormControlState():
Save webktiRelativePath.

* FormStateSignature() in form_controller.cc:
Increment the version string due to the format change.

* FileInputType::RestoreFormControlState():
Create |File| instances from FormControlState directly.  We used to
create a FileChooserFileInfoList from a FormControlState, and
FileInputType::CreateFileList() converted it to |File| instances. We
bypass FileChooserFileInoList because it can't represent
webkitRelativePath.

* FileInputType::FilesFromFormControlState(), HTMLInputElement::
  FilesFromFileInputFormControlState(), and SavedFormState::
  GetReferencedFilePaths():
Pass Vector<String> instead of FileChooserFileInfoList.  These
functions just need Vector<String>.

Bug:  124187 
Change-Id: I225463694d164c1f6ed1cb61da8a5bc42e2542c6
Reviewed-on: https://chromium-review.googlesource.com/c/1322671
Reviewed-by: Yoshifumi Inoue <yosin@chromium.org>
Commit-Queue: Kent Tamura <tkent@chromium.org>
Cr-Commit-Position: refs/heads/master@{#606286}
[modify] https://crrev.com/f81a5040023b4a9e865a28e097a04105fa447638/third_party/blink/renderer/core/html/forms/file_input_type.cc
[modify] https://crrev.com/f81a5040023b4a9e865a28e097a04105fa447638/third_party/blink/renderer/core/html/forms/file_input_type.h
[modify] https://crrev.com/f81a5040023b4a9e865a28e097a04105fa447638/third_party/blink/renderer/core/html/forms/form_controller.cc
[modify] https://crrev.com/f81a5040023b4a9e865a28e097a04105fa447638/third_party/blink/renderer/core/html/forms/html_input_element.cc
[modify] https://crrev.com/f81a5040023b4a9e865a28e097a04105fa447638/third_party/blink/renderer/core/html/forms/html_input_element.h

Project Member

Comment 33 by bugdroid1@chromium.org, Nov 8

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/f81a5040023b4a9e865a28e097a04105fa447638

commit f81a5040023b4a9e865a28e097a04105fa447638
Author: Kent Tamura <tkent@chromium.org>
Date: Thu Nov 08 02:12:21 2018

input[type=file]: Save and restore webkitRelativePath values

Before this CL, we didn't save webkitRelativePath values on saving
a tab session, and we computed them with the longest common ancestor
directory of all files on restoring the tab session. After this CL,
we save webkitRelativePath values, and restore them without finding
the common ancestor directory.  This CL is a preparation of fixing
 crbug.com/124187 .

* FileInputType::SaveFormControlState():
Save webktiRelativePath.

* FormStateSignature() in form_controller.cc:
Increment the version string due to the format change.

* FileInputType::RestoreFormControlState():
Create |File| instances from FormControlState directly.  We used to
create a FileChooserFileInfoList from a FormControlState, and
FileInputType::CreateFileList() converted it to |File| instances. We
bypass FileChooserFileInoList because it can't represent
webkitRelativePath.

* FileInputType::FilesFromFormControlState(), HTMLInputElement::
  FilesFromFileInputFormControlState(), and SavedFormState::
  GetReferencedFilePaths():
Pass Vector<String> instead of FileChooserFileInfoList.  These
functions just need Vector<String>.

Bug:  124187 
Change-Id: I225463694d164c1f6ed1cb61da8a5bc42e2542c6
Reviewed-on: https://chromium-review.googlesource.com/c/1322671
Reviewed-by: Yoshifumi Inoue <yosin@chromium.org>
Commit-Queue: Kent Tamura <tkent@chromium.org>
Cr-Commit-Position: refs/heads/master@{#606286}
[modify] https://crrev.com/f81a5040023b4a9e865a28e097a04105fa447638/third_party/blink/renderer/core/html/forms/file_input_type.cc
[modify] https://crrev.com/f81a5040023b4a9e865a28e097a04105fa447638/third_party/blink/renderer/core/html/forms/file_input_type.h
[modify] https://crrev.com/f81a5040023b4a9e865a28e097a04105fa447638/third_party/blink/renderer/core/html/forms/form_controller.cc
[modify] https://crrev.com/f81a5040023b4a9e865a28e097a04105fa447638/third_party/blink/renderer/core/html/forms/html_input_element.cc
[modify] https://crrev.com/f81a5040023b4a9e865a28e097a04105fa447638/third_party/blink/renderer/core/html/forms/html_input_element.h

Project Member

Comment 34 by bugdroid1@chromium.org, Nov 8

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/f81a5040023b4a9e865a28e097a04105fa447638

commit f81a5040023b4a9e865a28e097a04105fa447638
Author: Kent Tamura <tkent@chromium.org>
Date: Thu Nov 08 02:12:21 2018

input[type=file]: Save and restore webkitRelativePath values

Before this CL, we didn't save webkitRelativePath values on saving
a tab session, and we computed them with the longest common ancestor
directory of all files on restoring the tab session. After this CL,
we save webkitRelativePath values, and restore them without finding
the common ancestor directory.  This CL is a preparation of fixing
 crbug.com/124187 .

* FileInputType::SaveFormControlState():
Save webktiRelativePath.

* FormStateSignature() in form_controller.cc:
Increment the version string due to the format change.

* FileInputType::RestoreFormControlState():
Create |File| instances from FormControlState directly.  We used to
create a FileChooserFileInfoList from a FormControlState, and
FileInputType::CreateFileList() converted it to |File| instances. We
bypass FileChooserFileInoList because it can't represent
webkitRelativePath.

* FileInputType::FilesFromFormControlState(), HTMLInputElement::
  FilesFromFileInputFormControlState(), and SavedFormState::
  GetReferencedFilePaths():
Pass Vector<String> instead of FileChooserFileInfoList.  These
functions just need Vector<String>.

Bug:  124187 
Change-Id: I225463694d164c1f6ed1cb61da8a5bc42e2542c6
Reviewed-on: https://chromium-review.googlesource.com/c/1322671
Reviewed-by: Yoshifumi Inoue <yosin@chromium.org>
Commit-Queue: Kent Tamura <tkent@chromium.org>
Cr-Commit-Position: refs/heads/master@{#606286}
[modify] https://crrev.com/f81a5040023b4a9e865a28e097a04105fa447638/third_party/blink/renderer/core/html/forms/file_input_type.cc
[modify] https://crrev.com/f81a5040023b4a9e865a28e097a04105fa447638/third_party/blink/renderer/core/html/forms/file_input_type.h
[modify] https://crrev.com/f81a5040023b4a9e865a28e097a04105fa447638/third_party/blink/renderer/core/html/forms/form_controller.cc
[modify] https://crrev.com/f81a5040023b4a9e865a28e097a04105fa447638/third_party/blink/renderer/core/html/forms/html_input_element.cc
[modify] https://crrev.com/f81a5040023b4a9e865a28e097a04105fa447638/third_party/blink/renderer/core/html/forms/html_input_element.h

Created a chromestatus entry; https://www.chromestatus.com/feature/5000708122214400

Project Member

Comment 36 by bugdroid1@chromium.org, Nov 14

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/0d7a74576663b031696ca917057a67491d7b1230

commit 0d7a74576663b031696ca917057a67491d7b1230
Author: Kent Tamura <tkent@chromium.org>
Date: Wed Nov 14 02:08:02 2018

entries-api: Make webkitRelativePath interoperable

This CL makes webkitRelativePath IDL attribute behavior same as Edge,
Firefox, and Safari.  It returns relative path from the parent of the
selected directory.

* chrome/browser/file_select_helper.cc
* chrome/browser/file_select_helper.h
  Record a FilePath with which we started enumeration, and path it to
  FileSelectListener.

* android_webview/browser/aw_web_contents_delegate.cc
* chrome/browser/ssl/security_state_tab_helper_browsertest.cc
* content/browser/web_contents/web_contents_impl_browsertest.cc
* content/renderer/pepper/pepper_file_chooser_host_unittest.cc
* content/test/content_browser_test_utils_internal.cc
  Pass an empty FilePath to FileSelectListener.

* content/browser/frame_host/render_frame_host_impl.cc
* content/public/browser/file_select_listener.h
* third_party/blink/public/mojom/choosers/file_chooser.mojom
* third_party/blink/renderer/core/html/forms/file_chooser.h
* third_party/blink/renderer/core/html/forms/file_chooser.cc
  Pass a FilePath to FileInputType through FileSelectListener and mojo.

* third_party/blink/renderer/core/html/forms/file_input_type.cc
  Compute webkitRelativePath with the passed FilePath, instead of a
  common ancestor.

* third_party/WebKit/LayoutTests/fast/forms/resources/mock-file-chooser.js
  Support FileChooserResult.base_directory


Change-Id: I4c9f03b053b5a9230e954dcd216439d8c5c54d0b
Bug:  124187 
Reviewed-on: https://chromium-review.googlesource.com/c/1325579
Commit-Queue: Kent Tamura <tkent@chromium.org>
Reviewed-by: Richard Coles <torne@chromium.org>
Reviewed-by: Avi Drissman <avi@chromium.org>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Reviewed-by: Joshua Bell <jsbell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#607849}
[modify] https://crrev.com/0d7a74576663b031696ca917057a67491d7b1230/android_webview/browser/aw_web_contents_delegate.cc
[modify] https://crrev.com/0d7a74576663b031696ca917057a67491d7b1230/chrome/browser/file_select_helper.cc
[modify] https://crrev.com/0d7a74576663b031696ca917057a67491d7b1230/chrome/browser/file_select_helper.h
[modify] https://crrev.com/0d7a74576663b031696ca917057a67491d7b1230/chrome/browser/ssl/security_state_tab_helper_browsertest.cc
[modify] https://crrev.com/0d7a74576663b031696ca917057a67491d7b1230/content/browser/frame_host/render_frame_host_impl.cc
[modify] https://crrev.com/0d7a74576663b031696ca917057a67491d7b1230/content/browser/web_contents/web_contents_impl_browsertest.cc
[modify] https://crrev.com/0d7a74576663b031696ca917057a67491d7b1230/content/public/browser/file_select_listener.h
[modify] https://crrev.com/0d7a74576663b031696ca917057a67491d7b1230/content/renderer/pepper/pepper_file_chooser_host_unittest.cc
[modify] https://crrev.com/0d7a74576663b031696ca917057a67491d7b1230/content/test/content_browser_test_utils_internal.cc
[modify] https://crrev.com/0d7a74576663b031696ca917057a67491d7b1230/third_party/WebKit/LayoutTests/fast/forms/file/file-input-webkitdirectory-click-expected.txt
[modify] https://crrev.com/0d7a74576663b031696ca917057a67491d7b1230/third_party/WebKit/LayoutTests/fast/forms/file/file-input-webkitdirectory-key-enter-expected.txt
[modify] https://crrev.com/0d7a74576663b031696ca917057a67491d7b1230/third_party/WebKit/LayoutTests/fast/forms/file/file-input-webkitdirectory-key-enter-prevent-keypress-expected.txt
[modify] https://crrev.com/0d7a74576663b031696ca917057a67491d7b1230/third_party/WebKit/LayoutTests/fast/forms/file/file-input-webkitdirectory-key-space-expected.txt
[add] https://crrev.com/0d7a74576663b031696ca917057a67491d7b1230/third_party/WebKit/LayoutTests/fast/forms/file/file-webkitRelativePath.html
[modify] https://crrev.com/0d7a74576663b031696ca917057a67491d7b1230/third_party/WebKit/LayoutTests/fast/forms/resources/mock-file-chooser.js
[modify] https://crrev.com/0d7a74576663b031696ca917057a67491d7b1230/third_party/blink/public/mojom/choosers/file_chooser.mojom
[modify] https://crrev.com/0d7a74576663b031696ca917057a67491d7b1230/third_party/blink/renderer/core/html/forms/file_chooser.cc
[modify] https://crrev.com/0d7a74576663b031696ca917057a67491d7b1230/third_party/blink/renderer/core/html/forms/file_chooser.h
[modify] https://crrev.com/0d7a74576663b031696ca917057a67491d7b1230/third_party/blink/renderer/core/html/forms/file_input_type.cc
[modify] https://crrev.com/0d7a74576663b031696ca917057a67491d7b1230/third_party/blink/renderer/core/html/forms/file_input_type.h
[modify] https://crrev.com/0d7a74576663b031696ca917057a67491d7b1230/third_party/blink/renderer/core/html/forms/file_input_type_test.cc
[modify] https://crrev.com/0d7a74576663b031696ca917057a67491d7b1230/third_party/blink/renderer/core/html/forms/html_input_element_test.cc
[modify] https://crrev.com/0d7a74576663b031696ca917057a67491d7b1230/third_party/blink/renderer/core/html/forms/mock_file_chooser.h
[modify] https://crrev.com/0d7a74576663b031696ca917057a67491d7b1230/third_party/blink/renderer/core/page/chrome_client_impl_test.cc

Labels: Target-72
Status: Fixed (was: Started)

Sign in to add a comment