Update MIME type parser
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 23 Jan 2019 11:32:55 +0000 (11:32 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 23 Jan 2019 11:32:55 +0000 (11:32 +0000)
commit6953145a5f98292755af81a3559be2b24b4690a1
tree60515e82c22bc469a57e3b560fcacd2bdb03fef6
parent378dd09b02e7e836efa4f44519c4601ac84f0133
Update MIME type parser
https://bugs.webkit.org/show_bug.cgi?id=180526

Patch by Rob Buis <rbuis@igalia.com> on 2019-01-23
Reviewed by Frédéric Wang.

LayoutTests/imported/w3c:

Update improved test expectations.

* web-platform-tests/xhr/overridemimetype-blob-expected.txt:

Source/WebCore:

Add an enum to allow two modes of MIME type parsing, one mode
to keep supporting RFC2045 as before, and one mode to support
the updated MIME parser from mimesniff [1]. Mimesniff support
brings the following changes:
- allows parameter names without matching =value.
- skips whitespace after subtype, parameter value and before
  parameter name.
- lower cases MIME type and parameter name.
- parameter names parsed before are discarded.

The old mode is still used by CDM.cpp and MIMEHeader.cpp.

[1] https://mimesniff.spec.whatwg.org/

* Modules/encryptedmedia/CDM.cpp:
(WebCore::CDM::getSupportedCapabilitiesForAudioVideoType):
* platform/network/MIMEHeader.cpp:
(WebCore::MIMEHeader::parseHeader):
* platform/network/ParsedContentType.cpp:
(WebCore::DummyParsedContentType::setContentType const):
(WebCore::DummyParsedContentType::setContentTypeParameter const):
(WebCore::isQuotedStringTokenCharacter):
(WebCore::isTokenCharacter):
(WebCore::parseToken):
(WebCore::containsNonTokenCharacters):
(WebCore::parseQuotedString):
(WebCore::isNotForwardSlash):
(WebCore::isNotSemicolon):
(WebCore::isNotSemicolonOrEqualSign):
(WebCore::parseContentType):
(WebCore::isValidContentType):
(WebCore::ParsedContentType::ParsedContentType):
(WebCore::ParsedContentType::setContentType):
(WebCore::isNonTokenCharacter):
(WebCore::isNonQuotedStringTokenCharacter):
(WebCore::ParsedContentType::setContentTypeParameter):
* platform/network/ParsedContentType.h:

Test: web-platform-tests/xhr/overridemimetype-blob.html

Tools:

Add unit tests for both parse modes of ParsedContentType.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebCore/ParsedContentType.cpp: Added.
(TestWebKitAPI::TEST):

LayoutTests:

Adjust test expectation.

* http/tests/xmlhttprequest/post-blob-content-type-async-expected.txt:
* http/tests/xmlhttprequest/post-blob-content-type-sync-expected.txt:
* http/tests/xmlhttprequest/post-blob-content-type-tests.js:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@240331 268f45cc-cd09-0410-ab3c-d52691b4dbfc
14 files changed:
LayoutTests/ChangeLog
LayoutTests/http/tests/xmlhttprequest/post-blob-content-type-async-expected.txt
LayoutTests/http/tests/xmlhttprequest/post-blob-content-type-sync-expected.txt
LayoutTests/http/tests/xmlhttprequest/post-blob-content-type-tests.js
LayoutTests/imported/w3c/ChangeLog
LayoutTests/imported/w3c/web-platform-tests/xhr/overridemimetype-blob-expected.txt
Source/WebCore/ChangeLog
Source/WebCore/Modules/encryptedmedia/CDM.cpp
Source/WebCore/platform/network/MIMEHeader.cpp
Source/WebCore/platform/network/ParsedContentType.cpp
Source/WebCore/platform/network/ParsedContentType.h
Tools/ChangeLog
Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
Tools/TestWebKitAPI/Tests/WebCore/ParsedContentType.cpp [new file with mode: 0644]