Safari/WebView: `accept` attribute of `<input type="file">` does not work properly

Originator:jonathan
Number:rdar://36726477 Date Originated:22 Jan 2018
Status:Open Resolved:
Product:iOS + SDK Product Version:11.2.2
Classification:Bug Reproducible:Always
 
Summary:
The `accept` attribute of an `<input type="file">` restricts which file types may be selected in an HTML form. This does not work properly on iOS, both in Safari and UIWebView/WKWebView. A value of "application/pdf" should only allow PDF files, but iOS allows all file types. A value of "image/jpeg, application/pdf" should allow JPEG and PDF files, but iOS only allows JPEG files. This is especially problematic, as users now cannot select PDF files, while that should be possible.

Steps to Reproduce:
1. Open this example form in iOS (Safari/UIWebView/WKWebView): https://jsfiddle.net/Lcv9mznf/4/
2. Tap "Choose File" for the three inputs
3. Choose "Browse" to select a file from the system file picker
4. Navigate to an iCloud Drive folder containing various types of files (JPEG, PDF, …)

Expected Results:
- First input ("image/jpeg"): Only JPEG files can be selected
- Second input ("application/pdf"): Only PDF files can be selected
- Third input ("image/jpeg, application/pdf"): Only JPEG and PDF files can be selected

Actual Results:
- First input ("image/jpeg"): Only JPEG files can be selected (correct)
- Second input ("application/pdf"): All file types can be selected (INCORRECT)
- Third input ("image/jpeg, application/pdf"): Only JPEG files can be selected (INCORRECT)

Version/Build:
Tested on iOS 11.2.2 (15C202)
The bug has been present at least since iOS 9: https://stackoverflow.com/q/35195983/251760

Configuration:
iPhone 7 Plus (MN4M2ZD/A)

Notes:
The exact same issue also occurs when selecting files from Dropbox:
https://www.dropboxforum.com/t5/Manage-account/Dropbox-does-not-properly-support-HTML-input-accept-types-on-iOS/td-p/161522
Initially, I though it was a bug in the Dropbox file picker. However, now it also occurs with iCloud Drive, I suspect it is an issue between WebKit and UIDocumentPickerViewController.
A similar issue seems to occur with Google Drive: rdar://24187873

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!