Changeset 220312 in webkit


Ignore:
Timestamp:
Aug 5, 2017 12:57:55 AM (7 years ago)
Author:
BJ Burg
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.
Location:
trunk/Source/WebKit
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r220311 r220312  
     12017-08-05  Brian Burg  <bburg@apple.com>
     2
     3        Web Automation: files selected for upload should be matched against 'accept' attribute values case-insensitively
     4        https://bugs.webkit.org/show_bug.cgi?id=175191
     5        <rdar://problem/33725790>
     6
     7        Reviewed by Carlos Garcia Campos.
     8
     9        Values of the "accept" attribute are to be compared in a case-insensitive manner, per
     10        https://html.spec.whatwg.org/multipage/input.html#file-upload-state-(type=file)
     11
     12        Except for converting MIME types and extensions to lowercase, most of these changes
     13        were lost in a rebase prior to landing the patch.
     14
     15        * UIProcess/Automation/WebAutomationSession.cpp:
     16        (WebKit::fileCanBeAcceptedForUpload): Fix some issues:
     17        - Handle a file ending in a period.
     18        - Handle MIME type inference failing.
     19        - Convert extensions and MIMEs to lower case, per specification.
     20
     21        (WebKit::WebAutomationSession::handleRunOpenPanel):
     22        - Strip the leading period from file extensions.
     23        - These range converters crash unless the API::Array is retained by a local variable.
     24
    1252017-08-04  Youenn Fablet  <youenn@apple.com>
    226
  • trunk/Source/WebKit/UIProcess/Automation/WebAutomationSession.cpp

    r220222 r220312  
    542542        return false;
    543543
    544     String extension = filename.substring(dotOffset + 1);
     544    String extension = filename.substring(dotOffset + 1).convertToASCIILowercase();
     545    if (extension.isEmpty())
     546        return false;
     547
    545548    if (allowedFileExtensions.contains(extension))
    546549        return true;
    547550
    548     String mappedMIMEType = WebCore::MIMETypeRegistry::getMIMETypeForExtension(extension);
     551    String mappedMIMEType = WebCore::MIMETypeRegistry::getMIMETypeForExtension(extension).convertToASCIILowercase();
     552    if (mappedMIMEType.isEmpty())
     553        return false;
     554   
    549555    if (allowedMIMETypes.contains(mappedMIMEType))
    550556        return true;
     
    578584
    579585    HashSet<String> allowedMIMETypes;
    580     for (auto type : parameters.acceptMIMETypes()->elementsOfType<API::String>())
     586    auto acceptMIMETypes = parameters.acceptMIMETypes();
     587    for (auto type : acceptMIMETypes->elementsOfType<API::String>())
    581588        allowedMIMETypes.add(type->string());
    582589
    583590    HashSet<String> allowedFileExtensions;
    584     for (auto type : parameters.acceptFileExtensions()->elementsOfType<API::String>())
    585         allowedFileExtensions.add(type->string());
     591    auto acceptFileExtensions = parameters.acceptFileExtensions();
     592    for (auto type : acceptFileExtensions->elementsOfType<API::String>()) {
     593        // WebCore vends extensions with leading periods. Strip these to simplify matching later.
     594        String extension = type->string();
     595        ASSERT(extension.characterAt(0) == '.');
     596        allowedFileExtensions.add(extension.substring(1));
     597    }
    586598
    587599    // Per §14.3.10.5 in the W3C spec, if at least one file cannot be accepted, the command should fail.
Note: See TracChangeset for help on using the changeset viewer.