Bug 111687

Summary: FormData should allow setting filename to empty
Product: WebKit Reporter: Alexey Proskuryakov <ap>
Component: Page LoadingAssignee: Alexey Proskuryakov <ap>
Status: RESOLVED FIXED    
Severity: Normal CC: abarth, annevk, costan, dino, esprehn+autocc, michaeln, mifenton, ojan.autocc, tkent, webkit.review.bot
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on: 111765    
Bug Blocks:    
Attachments:
Description Flags
proposed fix beidson: review+

Description Alexey Proskuryakov 2013-03-06 22:58:47 PST
Per XMLHttpRequest spec, empty filename should be supported:

- Set its name to name.
- Set its value to value.
- Set its type to "text" if value is a string and "file" if it is a Blob.
- If its type is "file" set its filename to "blob".
- If its type is "file" and value is a File whose name attribute is not the empty string, set entry's filename to the attribute's value.
- If the filename parameter is not omitted set entry's filename to filename.

This makes sense, because empty form type=file controls are sent as files with empty name by normal form submission.

Also, this would be helpful for WebKit, because currently we have to simulate empty path with a File that has an empty path internally, which is an unfortunate hack. Using a blob would be nicer.
Comment 1 Alexey Proskuryakov 2013-03-06 23:12:07 PST
Created attachment 191928 [details]
proposed fix
Comment 2 Victor Costan 2013-03-06 23:21:46 PST
Thank you for cc-ing me on this! I will use the test structure you set up there for the tests in 111380.
Comment 3 Alexey Proskuryakov 2013-03-06 23:31:36 PST
> we have to simulate empty path with a File that has an empty path

This wasn't very clear, but the patch should speak louder than words.
Comment 4 Benjamin Poulain 2013-03-07 01:03:15 PST
Comment on attachment 191928 [details]
proposed fix

View in context: https://bugs.webkit.org/attachment.cgi?id=191928&action=review

> Source/WebCore/html/FileInputType.cpp:158
> +        encoding.appendBlob(element()->name(), BlobBuilder().getBlob("application/octet-stream"), emptyString());

ASCIILiteral("application/octet-stream")?
Comment 5 Victor Costan 2013-03-07 08:44:03 PST
Since BlobBuilder was deprecated in the spec, would it simplify the code if its implementation was moved into the Blob constructor?
 
I'm not saying that this should happen here, BTW. I'm mostly asking because I'd be interested in taking up the cleanup work, to learn more about the codebase.
Comment 6 Alexey Proskuryakov 2013-03-07 10:06:44 PST
> ASCIILiteral("application/octet-stream")?

Can do.

> Since BlobBuilder was deprecated in the spec, would it simplify the code if its implementation was moved into the Blob constructor?

Possibly. Currently, BlobBuilder interface is a bit too large to include into Blob, and it's oriented towards incremental building. But perhaps most of that is not needed any more, and can be simplified.

In this patch, I could have avoided using BlobBuilder, although I'm not sure if that's a win:

OwnPtr<BlobData> emptyBlobData = BlobData::create();
emptyBlobData->setContentType(ASCIILiteral("application/octet-stream"));
encoding.appendBlob(element()->name(), Blob::create(emptyBlobData.release(), 0), emptyString());
Comment 7 Brady Eidson 2013-03-07 10:19:30 PST
Comment on attachment 191928 [details]
proposed fix

R+ with ASCIILiteral fix
Comment 8 Victor Costan 2013-03-07 10:25:28 PST
I also don't think removing the BlobBuilder reference is a win. If that cleanup is ever desirable, I'd like to have a helper that makes this task a one-liner.
Comment 9 Alexey Proskuryakov 2013-03-07 10:27:36 PST
Committed <http://trac.webkit.org/changeset/145097>.
Comment 10 WebKit Review Bot 2013-03-07 12:29:34 PST
Re-opened since this is blocked by bug 111765
Comment 11 Adam Barth 2013-03-07 12:29:55 PST
ap and I discussed this topic on #webkit.  We're going to roll out the change for the time being.  I'm going to remove the ASSERT from the Chromium code and then re-land this patch.
Comment 12 Adam Barth 2013-03-07 13:31:38 PST
Chromium side-change is under review at https://codereview.chromium.org/12633004/
Comment 13 Alexey Proskuryakov 2013-03-07 14:53:19 PST
OK, so turns out that old and new code is equally wrong in this regard, but old code did not have an assertion to catch that.

What happens is that the object created here is deleted earlier than it should be - it is owned by DOMFormData, and that's destroyed at the end of FormSubmission::create(). So, a Blob or a File becomes unregistered in blob registry, and cannot be used when actually building form data stream in another process.

We should obviously keep uploaded objects alive while form submission takes place.

Anyway, I'm going to re-land the parts of this patch that actually implement what bug title says. This additional fix should be made separately.
Comment 14 Adam Barth 2013-03-07 14:59:58 PST
> Anyway, I'm going to re-land the parts of this patch that actually implement what bug title says. This additional fix should be made separately.

It's unclear to me whether I should land <https://codereview.chromium.org/12633004/>.
Comment 15 Alexey Proskuryakov 2013-03-07 15:05:24 PST
Re-landed safe parts in <http://trac.webkit.org/changeset/145142>. Filed bug 111778 to track the pre-existing issue.
Comment 16 Alexey Proskuryakov 2013-03-07 15:05:48 PST
> It's unclear to me whether I should land <https://codereview.chromium.org/12633004/>.

I don't think that it should be landed any more.
Comment 17 Adam Barth 2013-03-07 15:07:57 PST
> I don't think that it should be landed any more.

Thanks.  I've marked the code review as closed.
Comment 18 Alexey Proskuryakov 2013-03-07 15:09:55 PST
I appreciate your help dealing with this issue, and Michael's insight into the reasons of the assertion!
Comment 19 Michael Nordman 2013-03-07 15:11:02 PST
Fyi: I've been working towards fixing that for a while now. Its not just a problem with FormData. The changes I've got are simple enough but landing it is troublesome because I'm changing what the blob identifiers identify and I haven't come up with a great way to do that given the chromium/webkit split svn personality. 

webcore changes - https://codereview.chromium.org/11192017/
chromium changes - https://codereview.chromium.org/11410019/

I have been whittling down on the size of these changes by landing smaller parts independently. This small change awaiting review is a part of that...
   https://bugs.webkit.org/show_bug.cgi?id=108851
... but there come the time to change what the identifier identifies and I don't know how to cross that chasm quite yet.
Comment 20 Michael Nordman 2013-03-07 16:14:03 PST
Here's the umbrella bug open for that.
https://bugs.webkit.org/show_bug.cgi?id=108733
Comment 21 Dean Jackson 2013-03-07 16:33:28 PST
http/tests/misc/empty-file-formdata.html is failing on WK1 Mac after this
http://build.webkit.org/results/Apple%20MountainLion%20Release%20WK1%20(Tests)/r145143%20(7681)/results.html
Comment 22 Alexey Proskuryakov 2013-03-07 17:19:16 PST
Accidental commit of local changes, fixed that now.