Title: [220312] trunk/Source/WebKit
Revision
220312
Author
bb...@apple.com
Date
2017-08-05 00:57:55 -0700 (Sat, 05 Aug 2017)

Log Message

Web Automation: files selected for upload should be matched against 'accept' attribute values case-insensitively
https://bugs.webkit.org/show_bug.cgi?id=175191
<rdar://problem/33725790>

Reviewed by Carlos Garcia Campos.

Values of the "accept" attribute are to be compared in a case-insensitive manner, per
https://html.spec.whatwg.org/multipage/input.html#file-upload-state-(type=file)

Except for converting MIME types and extensions to lowercase, most of these changes
were lost in a rebase prior to landing the patch.

* UIProcess/Automation/WebAutomationSession.cpp:
(WebKit::fileCanBeAcceptedForUpload): Fix some issues:
- Handle a file ending in a period.
- Handle MIME type inference failing.
- Convert extensions and MIMEs to lower case, per specification.

(WebKit::WebAutomationSession::handleRunOpenPanel):
- Strip the leading period from file extensions.
- These range converters crash unless the API::Array is retained by a local variable.

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (220311 => 220312)


--- trunk/Source/WebKit/ChangeLog	2017-08-05 05:06:13 UTC (rev 220311)
+++ trunk/Source/WebKit/ChangeLog	2017-08-05 07:57:55 UTC (rev 220312)
@@ -1,3 +1,27 @@
+2017-08-05  Brian Burg  <bb...@apple.com>
+
+        Web Automation: files selected for upload should be matched against 'accept' attribute values case-insensitively
+        https://bugs.webkit.org/show_bug.cgi?id=175191
+        <rdar://problem/33725790>
+
+        Reviewed by Carlos Garcia Campos.
+
+        Values of the "accept" attribute are to be compared in a case-insensitive manner, per
+        https://html.spec.whatwg.org/multipage/input.html#file-upload-state-(type=file)
+
+        Except for converting MIME types and extensions to lowercase, most of these changes
+        were lost in a rebase prior to landing the patch.
+
+        * UIProcess/Automation/WebAutomationSession.cpp:
+        (WebKit::fileCanBeAcceptedForUpload): Fix some issues:
+        - Handle a file ending in a period.
+        - Handle MIME type inference failing.
+        - Convert extensions and MIMEs to lower case, per specification.
+
+        (WebKit::WebAutomationSession::handleRunOpenPanel):
+        - Strip the leading period from file extensions.
+        - These range converters crash unless the API::Array is retained by a local variable.
+
 2017-08-04  Youenn Fablet  <you...@apple.com>
 
         [Cache API] Add Cache and CacheStorage IDL definitions

Modified: trunk/Source/WebKit/UIProcess/Automation/WebAutomationSession.cpp (220311 => 220312)


--- trunk/Source/WebKit/UIProcess/Automation/WebAutomationSession.cpp	2017-08-05 05:06:13 UTC (rev 220311)
+++ trunk/Source/WebKit/UIProcess/Automation/WebAutomationSession.cpp	2017-08-05 07:57:55 UTC (rev 220312)
@@ -541,11 +541,17 @@
     if (dotOffset == notFound)
         return false;
 
-    String extension = filename.substring(dotOffset + 1);
+    String extension = filename.substring(dotOffset + 1).convertToASCIILowercase();
+    if (extension.isEmpty())
+        return false;
+
     if (allowedFileExtensions.contains(extension))
         return true;
 
-    String mappedMIMEType = WebCore::MIMETypeRegistry::getMIMETypeForExtension(extension);
+    String mappedMIMEType = WebCore::MIMETypeRegistry::getMIMETypeForExtension(extension).convertToASCIILowercase();
+    if (mappedMIMEType.isEmpty())
+        return false;
+    
     if (allowedMIMETypes.contains(mappedMIMEType))
         return true;
 
@@ -577,12 +583,18 @@
     }
 
     HashSet<String> allowedMIMETypes;
-    for (auto type : parameters.acceptMIMETypes()->elementsOfType<API::String>())
+    auto acceptMIMETypes = parameters.acceptMIMETypes();
+    for (auto type : acceptMIMETypes->elementsOfType<API::String>())
         allowedMIMETypes.add(type->string());
 
     HashSet<String> allowedFileExtensions;
-    for (auto type : parameters.acceptFileExtensions()->elementsOfType<API::String>())
-        allowedFileExtensions.add(type->string());
+    auto acceptFileExtensions = parameters.acceptFileExtensions();
+    for (auto type : acceptFileExtensions->elementsOfType<API::String>()) {
+        // WebCore vends extensions with leading periods. Strip these to simplify matching later.
+        String extension = type->string();
+        ASSERT(extension.characterAt(0) == '.');
+        allowedFileExtensions.add(extension.substring(1));
+    }
 
     // Per ยง14.3.10.5 in the W3C spec, if at least one file cannot be accepted, the command should fail.
     // The REST API service can tell that this failed by checking the "files" attribute of the input element.
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to