Bug 229456

Summary: [iOS] Unable to select files when the accept attribute is set to "*/*"
Product: WebKit Reporter: Lee Nave <nave>
Component: FormsAssignee: Aditya Keerthi <akeerthi>
Status: RESOLVED FIXED    
Severity: Normal CC: aestes, akeerthi, cdumez, kevin_neal, sabouhallawa, thorton, webkit-bug-importer, wenson_hsieh
Priority: P2 Keywords: InRadar
Version: Safari 14   
Hardware: iPhone / iPad   
OS: iOS 14   
Attachments:
Description Flags
Patch
none
Patch none

Description Lee Nave 2021-08-24 11:19:37 PDT
Given a web form with a file upload field with the accept attribute set to "*/*", like this:

<input type="file" accept="*/*">

Desktop browsers will ignore the accept attribute and allow any file to be uploaded.  On iOS, however, this is not the case and instead of being given the equivalent experience (which would be the "Photo Library / Take Photo / Browse" menu), the user is dropped into the file browser but without the ability to actually select any files (they are grayed out).

Granted, "*/*" is not a valid accept value per the spec. However, based on searching google for "ios upload grayed out" it is clear that many sites are setting this attribute and causing problems for iOS users. This behavior is difficult to diagnose and inconsistent with the desktop experience.

This can be easily reproduced here: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file
Comment 1 Chris Dumez 2021-08-24 12:31:18 PDT
"*/*" actually seems like a valid value according to the spec:
- https://html.spec.whatwg.org/multipage/input.html#attr-input-accept
says "A valid MIME type string with no parameters"

points to:
- https://mimesniff.spec.whatwg.org/#valid-mime-type-with-no-parameters

which points to:
- https://mimesniff.spec.whatwg.org/#valid-mime-type

which points to:
- https://datatracker.ietf.org/doc/html/rfc7231#section-3.1.1.1

says:
     media-type = type "/" subtype *( OWS ";" OWS parameter )
     type       = token
     subtype    = token

type and subtype are both tokens, defined here:
- https://datatracker.ietf.org/doc/html/rfc7230#section-3.2.6

so it seems like '*' is a valid token.
Comment 2 Lee Nave 2021-08-24 12:38:54 PDT
Ah, you're right, thanks!
Comment 3 Radar WebKit Bug Importer 2021-08-25 10:27:50 PDT
<rdar://problem/82346315>
Comment 4 Aditya Keerthi 2021-08-25 13:56:23 PDT
Created attachment 436422 [details]
Patch
Comment 5 Chris Dumez 2021-08-25 14:02:56 PDT
Comment on attachment 436422 [details]
Patch

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

r=me with comment

> Source/WebKit/UIProcess/ios/forms/WKFileUploadPanel.mm:358
> +        if ([mimeType caseInsensitiveCompare:@"*/*"] == NSOrderedSame)

nit: Do we really need a caseInsensitiveCompare for "*/*"?
Comment 6 Aditya Keerthi 2021-08-25 14:14:17 PDT
Created attachment 436425 [details]
Patch
Comment 7 Aditya Keerthi 2021-08-25 14:15:55 PDT
(In reply to Chris Dumez from comment #5)
> Comment on attachment 436422 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=436422&action=review
> 
> r=me with comment

Thanks for the review!
 
> > Source/WebKit/UIProcess/ios/forms/WKFileUploadPanel.mm:358
> > +        if ([mimeType caseInsensitiveCompare:@"*/*"] == NSOrderedSame)
> 
> nit: Do we really need a caseInsensitiveCompare for "*/*"?

Uploaded a new patch using `isEqualToString:`.
Comment 8 EWS 2021-08-25 20:08:49 PDT
Committed r281612 (240968@main): <https://commits.webkit.org/240968@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 436425 [details].
Comment 9 Lee Nave 2021-09-27 16:29:20 PDT
I just have to say, I'm really impressed with how quickly this bug was fixed. My first time cutting a WebKit issue and was expecting this to sit uncommented and then closed eventually for "no activity" or any of the other outcomes that seem common with large open-source projects supported by any of the Big 5. Very glad to be proven wrong.

My only complaints is that I was looking forward to figuring out WebKit development and fixing it myself :-)