Title: [236663] trunk

Diff

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (236662 => 236663)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2018-10-01 16:17:29 UTC (rev 236662)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2018-10-01 16:17:36 UTC (rev 236663)
@@ -1,3 +1,12 @@
+2018-10-01  Rob Buis  <rb...@igalia.com>
+
+        Align XMLHttpRequest's overrideMimeType() with the standard
+        https://bugs.webkit.org/show_bug.cgi?id=169276
+
+        Reviewed by Chris Dumez.
+
+        * web-platform-tests/xhr/overridemimetype-invalid-mime-type-expected.txt:
+
 2018-10-01  Chris Dumez  <cdu...@apple.com>
 
         Make crossOriginObject.then undefined for promises

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/xhr/overridemimetype-invalid-mime-type-expected.txt (236662 => 236663)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/xhr/overridemimetype-invalid-mime-type-expected.txt	2018-10-01 16:17:29 UTC (rev 236662)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/xhr/overridemimetype-invalid-mime-type-expected.txt	2018-10-01 16:17:36 UTC (rev 236663)
@@ -1,5 +1,5 @@
 
 PASS Bogus MIME type does not override encoding 
-FAIL Bogus MIME type does not override encoding, 2 assert_equals: expected "ΓΏ" but got "\x1a"
+PASS Bogus MIME type does not override encoding, 2 
 PASS Bogus MIME type does override MIME type 
 

Modified: trunk/Source/WebCore/ChangeLog (236662 => 236663)


--- trunk/Source/WebCore/ChangeLog	2018-10-01 16:17:29 UTC (rev 236662)
+++ trunk/Source/WebCore/ChangeLog	2018-10-01 16:17:36 UTC (rev 236663)
@@ -1,3 +1,29 @@
+2018-10-01  Rob Buis  <rb...@igalia.com>
+
+        Align XMLHttpRequest's overrideMimeType() with the standard
+        https://bugs.webkit.org/show_bug.cgi?id=169276
+
+        Reviewed by Chris Dumez.
+
+        Implement the overrideMimeType() as specified in that standard, i.e.
+        add a check that the passed mime type is valid and if not fallback
+        to application/octet-stream.
+
+        In order for this patch to have any effect, I went ahead and
+        made an improvement to the ContentType parsing, parseContentType now
+        will reject mime types that do not match the type / subtype format, I
+        believe this is required by both RFC2045 and mimesniff specs.
+
+        This behavior matches Chrome and Firefox.
+
+        Test: web-platform-tests/xhr/overridemimetype-invalid-mime-type.htm
+
+        * platform/network/ParsedContentType.cpp:
+        (WebCore::parseContentType):
+        * xml/XMLHttpRequest.cpp:
+        (WebCore::XMLHttpRequest::overrideMimeType):
+
+
 2018-10-01  Chris Dumez  <cdu...@apple.com>
 
         Make crossOriginObject.then undefined for promises

Modified: trunk/Source/WebCore/platform/network/ParsedContentType.cpp (236662 => 236663)


--- trunk/Source/WebCore/platform/network/ParsedContentType.cpp	2018-10-01 16:17:29 UTC (rev 236662)
+++ trunk/Source/WebCore/platform/network/ParsedContentType.cpp	2018-10-01 16:17:36 UTC (rev 236663)
@@ -160,14 +160,32 @@
         return false;
     }
 
+    unsigned contentTypeStart = index;
+    auto typeRange = parseToken(contentType, index);
+    if (!typeRange.second) {
+        LOG_ERROR("Invalid Content-Type, invalid type value.");
+        return false;
+    }
+
+    if (contentType[index++] != '/') {
+        LOG_ERROR("Invalid Content-Type, missing '/'.");
+        return false;
+    }
+
+    auto subTypeRange = parseToken(contentType, index);
+    if (!subTypeRange.second) {
+        LOG_ERROR("Invalid Content-Type, invalid subtype value.");
+        return false;
+    }
+
     // There should not be any quoted strings until we reach the parameters.
-    size_t semiColonIndex = contentType.find(';', index);
+    size_t semiColonIndex = contentType.find(';', contentTypeStart);
     if (semiColonIndex == notFound) {
-        receiver.setContentType(SubstringRange(index, contentTypeLength - index));
+        receiver.setContentType(SubstringRange(contentTypeStart, contentTypeLength - contentTypeStart));
         return true;
     }
 
-    receiver.setContentType(SubstringRange(index, semiColonIndex - index));
+    receiver.setContentType(SubstringRange(contentTypeStart, semiColonIndex - contentTypeStart));
     index = semiColonIndex + 1;
     while (true) {
         skipSpaces(contentType, index);

Modified: trunk/Source/WebCore/xml/XMLHttpRequest.cpp (236662 => 236663)


--- trunk/Source/WebCore/xml/XMLHttpRequest.cpp	2018-10-01 16:17:29 UTC (rev 236662)
+++ trunk/Source/WebCore/xml/XMLHttpRequest.cpp	2018-10-01 16:17:36 UTC (rev 236663)
@@ -776,12 +776,15 @@
     unsetPendingActivity(this);
 }
 
-ExceptionOr<void> XMLHttpRequest::overrideMimeType(const String& override)
+ExceptionOr<void> XMLHttpRequest::overrideMimeType(const String& mimeType)
 {
     if (readyState() == LOADING || readyState() == DONE)
         return Exception { InvalidStateError };
 
-    m_mimeTypeOverride = override;
+    m_mimeTypeOverride = "application/octet-stream"_s;
+    if (isValidContentType(mimeType))
+        m_mimeTypeOverride = mimeType;
+
     return { };
 }
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to