Bug 185416 - Empty <input type=file> is represented incorrectly in FormData
Summary: Empty <input type=file> is represented incorrectly in FormData
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: DOM (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2018-05-08 02:01 PDT by Anne van Kesteren
Modified: 2021-11-16 18:11 PST (History)
9 users (show)

See Also:


Attachments
Patch (4.17 KB, patch)
2021-11-15 00:42 PST, Andreu Botella
no flags Details | Formatted Diff | Diff
Patch (4.18 KB, patch)
2021-11-15 21:45 PST, Andreu Botella
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Anne van Kesteren 2018-05-08 02:01:20 PDT
Test: https://github.com/w3c/web-platform-tests/pull/10865. (Discovered while making an editorial change to the HTML Standard: https://github.com/whatwg/html/pull/3658.)
Comment 1 Alexey Proskuryakov 2018-05-09 23:38:31 PDT
Same as bug 184490? This bug has no substance other than the title and some links that sound like they would take excessive time to turn into actionable information.
Comment 2 Andreu Botella 2021-11-15 00:35:54 PST
It seems like this bug was about how a FormData object should represent empty <input type="file"> entries with an "application/octet-stream" content type. That is what the WPT PR is testing (although that test file has since been expanded to cover bug 221549), and see https://github.com/whatwg/html/pull/3658#discussion_r185426252 re: the conversation in the editorial change to HTML.
Comment 3 Andreu Botella 2021-11-15 00:42:54 PST
Created attachment 444216 [details]
Patch
Comment 4 Andreu Botella 2021-11-15 21:45:52 PST
Created attachment 444343 [details]
Patch
Comment 5 EWS 2021-11-16 07:24:25 PST
Committed r285861 (244287@main): <https://commits.webkit.org/244287@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 444343 [details].
Comment 6 Radar WebKit Bug Importer 2021-11-16 07:25:23 PST
<rdar://problem/85457351>
Comment 7 Darin Adler 2021-11-16 15:56:30 PST
Comment on attachment 444343 [details]
Patch

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

> Source/WebCore/html/FileInputType.cpp:189
> +        auto file = File::create(
> +            document,
> +            Blob::create(document, { }, "application/octet-stream"),
> +            emptyString());

This vertical formatting is not normally WebKit coding style, although it is technically allowed. I would prefer not to switch to it.

Writing "application/octet-stream" here isn’t as good as the WebCore::defaultMIMEType() function, which is more efficient than creating a string from a C literal each time, and it's also good to not have to worry about typos. We should use that function here.

As a follow-up, someone should also use that function in at least: WebCore::FileReaderLoader::convertToDataURL, WebCore::FormData::appendMultiPartFileValue, WebCore::XMLHttpRequest::overrideMimeType, and WebKit::LegacyDownloadClient::legacyDidStart. And we should also consider making a function for comparing the string for use in suggestedFilenameWithMIMEType and WebKit::NetworkResourceLoader::didReceiveResponse.
Comment 8 Darin Adler 2021-11-16 15:58:19 PST
Comment on attachment 444343 [details]
Patch

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

> Source/WebCore/html/FileInputType.cpp:182
> +    // application/octet-stream content type. Null would be more logical, but

I don’t think this comment change is an improvement; mentioning exactly what the code does is a non-goal for comments. The comment needs to cover "why", but no reason for it to say exactly "what".
Comment 9 Andreu Botella 2021-11-16 17:18:50 PST
Comment on attachment 444343 [details]
Patch

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

>> Source/WebCore/html/FileInputType.cpp:182
>> +    // application/octet-stream content type. Null would be more logical, but
> 
> I don’t think this comment change is an improvement; mentioning exactly what the code does is a non-goal for comments. The comment needs to cover "why", but no reason for it to say exactly "what".

I read "empty" as meaning "with the default settings", which would include an empty content-type. But you're right, the code makes that clear anyway. I'll revert this change.

>> Source/WebCore/html/FileInputType.cpp:189
>> +            emptyString());
> 
> This vertical formatting is not normally WebKit coding style, although it is technically allowed. I would prefer not to switch to it.
> 
> Writing "application/octet-stream" here isn’t as good as the WebCore::defaultMIMEType() function, which is more efficient than creating a string from a C literal each time, and it's also good to not have to worry about typos. We should use that function here.
> 
> As a follow-up, someone should also use that function in at least: WebCore::FileReaderLoader::convertToDataURL, WebCore::FormData::appendMultiPartFileValue, WebCore::XMLHttpRequest::overrideMimeType, and WebKit::LegacyDownloadClient::legacyDidStart. And we should also consider making a function for comparing the string for use in suggestedFilenameWithMIMEType and WebKit::NetworkResourceLoader::didReceiveResponse.

I think this code was reformatted by my IDE, using clang-format I believe, and since webkit-patch did not complain, I assumed that was fine. My bad for not actually checking that it followed the coding style. I suppose the right way would be having all the parameters in one line?

I did not know that WebCore::defaultMIMEType() was a thing.

Should I open a new bug for these changes?
Comment 10 Darin Adler 2021-11-16 17:37:40 PST
(In reply to Andreu Botella from comment #9)
> I think this code was reformatted by my IDE, using clang-format I believe,
> and since webkit-patch did not complain, I assumed that was fine. My bad for
> not actually checking that it followed the coding style. I suppose the right
> way would be having all the parameters in one line?

I think so.

> Should I open a new bug for these changes?

Sure, why not?
Comment 11 Andreu Botella 2021-11-16 18:11:16 PST
Fixing the code review suggestions in https://bugs.webkit.org/show_bug.cgi?id=233229