WebKit Bugzilla
Attachment 356923 Details for
Bug 180526
: Update MIME type parser
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch
bug-180526-20181209174659.patch (text/plain), 14.35 KB, created by
Rob Buis
on 2018-12-09 08:46:59 PST
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Rob Buis
Created:
2018-12-09 08:46:59 PST
Size:
14.35 KB
patch
obsolete
>Subversion Revision: 239019 >diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog >index 24f4f03fbe6767ff5798018ba4b8adb39bbf2bdc..509c61ce4821516947347f168b9a0f4d58371b9c 100644 >--- a/Source/WebCore/ChangeLog >+++ b/Source/WebCore/ChangeLog >@@ -1,3 +1,23 @@ >+2018-12-09 Rob Buis <rbuis@igalia.com> >+ >+ Update MIME type parser >+ https://bugs.webkit.org/show_bug.cgi?id=180526 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Test: web-platform-tests/xhr/overridemimetype-blob.html >+ >+ * platform/network/ParsedContentType.cpp: >+ (WebCore::DummyParsedContentType::setContentTypeParameter const): >+ (WebCore::parseContentType): >+ (WebCore::isValidContentType): >+ (WebCore::ParsedContentType::ParsedContentType): >+ (WebCore::ParsedContentType::setContentTypeParameter): >+ * platform/network/ParsedContentType.h: >+ * xml/XMLHttpRequest.cpp: >+ (WebCore::XMLHttpRequest::send): >+ (WebCore::XMLHttpRequest::overrideMimeType): >+ > 2018-12-09 Commit Queue <commit-queue@webkit.org> > > Unreviewed, rolling out r239010. >diff --git a/Source/WebCore/platform/network/ParsedContentType.cpp b/Source/WebCore/platform/network/ParsedContentType.cpp >index d729a05dbc0a528172a48ea9371cd8c51f3e1002..737d0444254ea09ce8a4f51e51d4a4d5d8054f86 100644 >--- a/Source/WebCore/platform/network/ParsedContentType.cpp >+++ b/Source/WebCore/platform/network/ParsedContentType.cpp >@@ -39,7 +39,7 @@ namespace WebCore { > class DummyParsedContentType { > public: > void setContentType(const SubstringRange&) const { } >- void setContentTypeParameter(const SubstringRange&, const SubstringRange&) const { } >+ void setContentTypeParameter(const SubstringRange&, const SubstringRange&, Spec) const { } > }; > > static void skipSpaces(const String& input, unsigned& startIndex) >@@ -152,7 +152,7 @@ static String substringForRange(const String& string, const SubstringRange& rang > // ; to use within parameter values > > template <class ReceiverType> >-bool parseContentType(const String& contentType, ReceiverType& receiver) >+bool parseContentType(const String& contentType, ReceiverType& receiver, Spec spec) > { > unsigned index = 0; > unsigned contentTypeLength = contentType.length(); >@@ -192,15 +192,26 @@ bool parseContentType(const String& contentType, ReceiverType& receiver) > while (true) { > skipSpaces(contentType, index); > auto keyRange = parseToken(contentType, index); >- if (!keyRange || index >= contentTypeLength) { >+ if (!keyRange || (spec == Spec::RFC2045 && index >= contentTypeLength)) { > LOG_ERROR("Invalid Content-Type parameter name."); > return false; > } > > // Should we tolerate spaces here? >- if (contentType[index++] != '=' || index >= contentTypeLength) { >- LOG_ERROR("Invalid Content-Type malformed parameter."); >- return false; >+ if (spec == Spec::RFC2045) { >+ if (contentType[index++] != '=' || index >= contentTypeLength) { >+ LOG_ERROR("Invalid Content-Type malformed parameter."); >+ return false; >+ } >+ } else { >+ if (index >= contentTypeLength) >+ break; >+ if (contentType[index] != '=' && contentType[index] != ';') { >+ LOG_ERROR("Invalid Content-Type malformed parameter."); >+ return false; >+ } >+ if (contentType[index++] == ';') >+ continue; > } > > // Should we tolerate spaces here? >@@ -208,21 +219,23 @@ bool parseContentType(const String& contentType, ReceiverType& receiver) > std::optional<SubstringRange> valueRange; > if (contentType[index] == '"') > valueRange = parseQuotedString(contentType, index); >- else >+ else { > valueRange = parseToken(contentType, index); >+ if (spec == Spec::MimeSniff) >+ skipSpaces(contentType, index); >+ } > > if (!valueRange) { > LOG_ERROR("Invalid Content-Type, invalid parameter value."); > return false; > } > >- // Should we tolerate spaces here? > if (index < contentTypeLength && contentType[index++] != ';') { > LOG_ERROR("Invalid Content-Type, invalid character at the end of key/value parameter."); > return false; > } > >- receiver.setContentTypeParameter(*keyRange, *valueRange); >+ receiver.setContentTypeParameter(*keyRange, *valueRange, spec); > > if (index >= contentTypeLength) > return true; >@@ -231,19 +244,19 @@ bool parseContentType(const String& contentType, ReceiverType& receiver) > return true; > } > >-bool isValidContentType(const String& contentType) >+bool isValidContentType(const String& contentType, Spec spec) > { > if (contentType.contains('\r') || contentType.contains('\n')) > return false; > > DummyParsedContentType parsedContentType = DummyParsedContentType(); >- return parseContentType<DummyParsedContentType>(contentType, parsedContentType); >+ return parseContentType<DummyParsedContentType>(contentType, parsedContentType, spec); > } > >-ParsedContentType::ParsedContentType(const String& contentType) >+ParsedContentType::ParsedContentType(const String& contentType, Spec spec) > : m_contentType(contentType.stripWhiteSpace()) > { >- parseContentType<ParsedContentType>(m_contentType, *this); >+ parseContentType<ParsedContentType>(m_contentType, *this, spec); > } > > String ParsedContentType::charset() const >@@ -266,9 +279,10 @@ void ParsedContentType::setContentType(const SubstringRange& contentRange) > m_mimeType = substringForRange(m_contentType, contentRange).stripWhiteSpace(); > } > >-void ParsedContentType::setContentTypeParameter(const SubstringRange& key, const SubstringRange& value) >+void ParsedContentType::setContentTypeParameter(const SubstringRange& key, const SubstringRange& value, Spec spec) > { >- m_parameters.set(substringForRange(m_contentType, key), substringForRange(m_contentType, value)); >+ if (spec == Spec::RFC2045 || !m_parameters.contains(substringForRange(m_contentType, key))) >+ m_parameters.set(substringForRange(m_contentType, key), substringForRange(m_contentType, value)); > } > > } >diff --git a/Source/WebCore/platform/network/ParsedContentType.h b/Source/WebCore/platform/network/ParsedContentType.h >index 6363b3e4d63587890a3cc8c11c56890abd19d0ee..d4705cfaad53e32d945a6dedb63e5c9c9d6cb4de 100644 >--- a/Source/WebCore/platform/network/ParsedContentType.h >+++ b/Source/WebCore/platform/network/ParsedContentType.h >@@ -36,14 +36,18 @@ > > namespace WebCore { > >+enum class Spec { >+ RFC2045, >+ MimeSniff >+}; > // <index, length> > typedef std::pair<unsigned, unsigned> SubstringRange; >-bool isValidContentType(const String&); >+bool isValidContentType(const String&, Spec = Spec::RFC2045); > > // FIXME: add support for comments. > class ParsedContentType { > public: >- explicit ParsedContentType(const String&); >+ explicit ParsedContentType(const String&, Spec = Spec::RFC2045); > > String mimeType() const { return m_mimeType; } > String charset() const; >@@ -54,9 +58,9 @@ public: > > private: > template<class ReceiverType> >- friend bool parseContentType(const String&, ReceiverType&); >+ friend bool parseContentType(const String&, ReceiverType&, Spec); > void setContentType(const SubstringRange&); >- void setContentTypeParameter(const SubstringRange&, const SubstringRange&); >+ void setContentTypeParameter(const SubstringRange&, const SubstringRange&, Spec); > > typedef HashMap<String, String> KeyValuePairs; > String m_contentType; >diff --git a/Source/WebCore/xml/XMLHttpRequest.cpp b/Source/WebCore/xml/XMLHttpRequest.cpp >index b9eccf352fa940749e671dfef6e6f8e7b0905a18..664216d365576ec5d8be7ec5a4ec9f3d179b02a1 100644 >--- a/Source/WebCore/xml/XMLHttpRequest.cpp >+++ b/Source/WebCore/xml/XMLHttpRequest.cpp >@@ -525,7 +525,7 @@ ExceptionOr<void> XMLHttpRequest::send(Blob& body) > if (m_method != "GET" && m_method != "HEAD" && m_url.protocolIsInHTTPFamily()) { > if (!m_requestHeaders.contains(HTTPHeaderName::ContentType)) { > const String& blobType = body.type(); >- if (!blobType.isEmpty() && isValidContentType(blobType)) >+ if (!blobType.isEmpty() && isValidContentType(blobType, Spec::MimeSniff)) > m_requestHeaders.set(HTTPHeaderName::ContentType, blobType); > else { > // From FileAPI spec, whenever media type cannot be determined, empty string must be returned. >@@ -785,7 +785,7 @@ ExceptionOr<void> XMLHttpRequest::overrideMimeType(const String& mimeType) > return Exception { InvalidStateError }; > > m_mimeTypeOverride = "application/octet-stream"_s; >- if (isValidContentType(mimeType)) >+ if (isValidContentType(mimeType, Spec::MimeSniff)) > m_mimeTypeOverride = mimeType; > > return { }; >diff --git a/LayoutTests/imported/w3c/ChangeLog b/LayoutTests/imported/w3c/ChangeLog >index c9bfe6214271411a524d66dc09a3d6975b12cdbf..3df12cd6fbea51dec21e36c49cd8ed031ff6e1c1 100644 >--- a/LayoutTests/imported/w3c/ChangeLog >+++ b/LayoutTests/imported/w3c/ChangeLog >@@ -1,3 +1,12 @@ >+2018-12-09 Rob Buis <rbuis@igalia.com> >+ >+ Update MIME type parser >+ https://bugs.webkit.org/show_bug.cgi?id=180526 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ * web-platform-tests/xhr/overridemimetype-blob-expected.txt: >+ > 2018-12-05 Youenn Fablet <youenn@apple.com> > > [iOS] Layout Test imported/w3c/web-platform-tests/service-workers/service-worker/fetch-cors-xhr.https.html is a flaky failure >diff --git a/LayoutTests/imported/w3c/web-platform-tests/xhr/overridemimetype-blob-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/xhr/overridemimetype-blob-expected.txt >index 02561ca2e3f97639025137c90de8837a1b1d306b..6be6d22ca73074081a9e8eb1f5ed91efdb25c58e 100644 >--- a/LayoutTests/imported/w3c/web-platform-tests/xhr/overridemimetype-blob-expected.txt >+++ b/LayoutTests/imported/w3c/web-platform-tests/xhr/overridemimetype-blob-expected.txt >@@ -17,9 +17,9 @@ FAIL 12) MIME types need to be parsed and serialized: text/html;charset='gbk' as > FAIL 13) MIME types need to be parsed and serialized: text/html;charset='gbk assert_equals: expected "text/html;charset='gbk" but got "text/html" > FAIL 14) MIME types need to be parsed and serialized: text/html;charset=gbk' assert_equals: expected "text/html;charset=gbk'" but got "text/html" > FAIL 15) MIME types need to be parsed and serialized: text/html;charset=';charset=GBK assert_equals: expected "text/html;charset='" but got "text/html" >-FAIL 16) MIME types need to be parsed and serialized: text/html;test;charset=gbk assert_equals: expected "text/html;charset=gbk" but got "application/octet-stream" >+FAIL 16) MIME types need to be parsed and serialized: text/html;test;charset=gbk assert_equals: expected "text/html;charset=gbk" but got "text/html" > FAIL 17) MIME types need to be parsed and serialized: text/html;test=;charset=gbk assert_equals: expected "text/html;charset=gbk" but got "application/octet-stream" >-FAIL 18) MIME types need to be parsed and serialized: text/html;';charset=gbk assert_equals: expected "text/html;charset=gbk" but got "application/octet-stream" >+FAIL 18) MIME types need to be parsed and serialized: text/html;';charset=gbk assert_equals: expected "text/html;charset=gbk" but got "text/html" > FAIL 19) MIME types need to be parsed and serialized: text/html;";charset=gbk assert_equals: expected "text/html;charset=gbk" but got "application/octet-stream" > FAIL 20) MIME types need to be parsed and serialized: text/html ; ; charset=gbk assert_equals: expected "text/html;charset=gbk" but got "application/octet-stream" > FAIL 21) MIME types need to be parsed and serialized: text/html;;;;charset=gbk assert_equals: expected "text/html;charset=gbk" but got "application/octet-stream" >@@ -40,7 +40,7 @@ FAIL 35) MIME types need to be parsed and serialized: text/html;0123456789012345 > PASS 36) MIME types need to be parsed and serialized: 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789/0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 > FAIL 37) MIME types need to be parsed and serialized: !#$%&'*+-.^_`|~0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz/!#$%&'*+-.^_`|~0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz;!#$%&'*+-.^_`|~0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz=!#$%&'*+-.^_`|~0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz assert_equals: expected "!#$%&'*+-.^_`|~0123456789abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz/!#$%&'*+-.^_`|~0123456789abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz;!#$%&'*+-.^_`|~0123456789abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz=!#$%&'*+-.^_`|~0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" but got "!#$%&'*+-.^_`|~0123456789abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz/!#$%&'*+-.^_`|~0123456789abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz" > FAIL 38) MIME types need to be parsed and serialized: x/x;x=" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~ Â ¡¢£¤¥¦§¨©ª«¬Â®¯°±²³´µ¶·¸¹º»¼½¾¿ÃÃÃÃÃà ÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃà áâãäåæçèéêëìÃîïðñòóôõö÷øùúûüýþÿ" assert_equals: expected "x/x;x=\"\t !\\\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~ Â ¡¢£¤¥¦§¨©ª«¬Â®¯°±²³´µ¶·¸¹º»¼½¾¿ÃÃÃÃÃà ÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃà áâãäåæçèéêëìÃîïðñòóôõö÷øùúûüýþÿ\"" but got "x/x" >-FAIL 39) MIME types need to be parsed and serialized: x/x;test assert_equals: expected "x/x" but got "application/octet-stream" >+PASS 39) MIME types need to be parsed and serialized: x/x;test > FAIL 40) MIME types need to be parsed and serialized: x/x;test="\ assert_equals: expected "x/x;test=\"\\\\"" but got "application/octet-stream" > FAIL 41) MIME types need to be parsed and serialized: x/x;x= assert_equals: expected "x/x" but got "application/octet-stream" > FAIL 42) MIME types need to be parsed and serialized: x/x;x= assert_equals: expected "x/x" but got "application/octet-stream"
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 180526
:
348014
|
356923
|
356928
|
357400
|
357401
|
357403
|
357443
|
357469
|
357682
|
357684
|
357687
|
357690
|
357691
|
357702
|
358515
|
358898
|
358906
|
358907
|
358917
|
359860
|
360118
|
360123
|
360129
|
360134
|
360136
|
360144
|
360303
|
360343
|
360350
|
360355
|
362245
|
362316
|
362323
|
362342
|
362348
|
362360
|
362378
|
362384
|
362387
|
362390
|
362397
|
362416
|
362418
|
362430
|
362437
|
362483
|
362486
|
362497
|
362506
|
362526
|
390349