Title: [276986] trunk
Revision
276986
Author
cdu...@apple.com
Date
2021-05-04 15:37:08 -0700 (Tue, 04 May 2021)

Log Message

Blob contentType with charset renders html as plain text
https://bugs.webkit.org/show_bug.cgi?id=225226

Reviewed by Alex Christensen.

Source/WebCore:

Our code would use the Blob's Content-Type (media type) as a MIME type internally. As a result, if the Blob's
media type would contain anything besides the MIME type (e.g. a charget), then it would lead to failures.

Test: fast/files/blob-with-charget-as-main-resource.html

* platform/network/BlobResourceHandle.cpp:
(WebCore::BlobResourceHandle::notifyResponseOnSuccess):
* platform/network/HTTPParsers.h:

Source/WebKit:

Our code would use the Blob's Content-Type (media type) as a MIME type internally. As a result, if the Blob's
media type would contain anything besides the MIME type (e.g. a charget), then it would lead to failures.

* NetworkProcess/NetworkDataTaskBlob.cpp:
(WebKit::NetworkDataTaskBlob::dispatchDidReceiveResponse):

LayoutTests:

Add layout test coverage.

* fast/files/blob-with-charget-as-main-resource-expected.html: Added.
* fast/files/blob-with-charget-as-main-resource.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (276985 => 276986)


--- trunk/LayoutTests/ChangeLog	2021-05-04 22:29:04 UTC (rev 276985)
+++ trunk/LayoutTests/ChangeLog	2021-05-04 22:37:08 UTC (rev 276986)
@@ -1,3 +1,15 @@
+2021-05-04  Chris Dumez  <cdu...@apple.com>
+
+        Blob contentType with charset renders html as plain text
+        https://bugs.webkit.org/show_bug.cgi?id=225226
+
+        Reviewed by Alex Christensen.
+
+        Add layout test coverage.
+
+        * fast/files/blob-with-charget-as-main-resource-expected.html: Added.
+        * fast/files/blob-with-charget-as-main-resource.html: Added.
+
 2021-05-04  Cameron McCormack  <hey...@apple.com>
 
         Handle clamping of heights for images affected by background-size and EXIF orientation correctly

Added: trunk/LayoutTests/fast/files/blob-with-charget-as-main-resource-expected.html (0 => 276986)


--- trunk/LayoutTests/fast/files/blob-with-charget-as-main-resource-expected.html	                        (rev 0)
+++ trunk/LayoutTests/fast/files/blob-with-charget-as-main-resource-expected.html	2021-05-04 22:37:08 UTC (rev 276986)
@@ -0,0 +1,24 @@
+<!DOCTYPE html>
+<html>
+<body>
+<p>This frame should have a blue background.</p>
+<iframe></iframe>
+<script>
+if (window.testRunner)
+    testRunner.waitUntilDone();
+var html = `
+<style>
+body { 
+  background: blue; 
+}
+</style>
+`;
+var iframe = document.querySelector("iframe");
+iframe._onload_ = () => {
+    if (window.testRunner)
+        testRunner.notifyDone();
+};
+iframe.srcdoc = html;
+</script>
+</body>
+</html>

Added: trunk/LayoutTests/fast/files/blob-with-charget-as-main-resource.html (0 => 276986)


--- trunk/LayoutTests/fast/files/blob-with-charget-as-main-resource.html	                        (rev 0)
+++ trunk/LayoutTests/fast/files/blob-with-charget-as-main-resource.html	2021-05-04 22:37:08 UTC (rev 276986)
@@ -0,0 +1,25 @@
+<!DOCTYPE html>
+<html>
+<body>
+<p>This frame should have a blue background.</p>
+<iframe></iframe>
+<script>
+if (window.testRunner)
+    testRunner.waitUntilDone();
+var html = `
+<style>
+body { 
+    background: blue; 
+}
+</style>
+`;
+var blob = new Blob([html], {type: 'text/html; charset=UTF-8'});
+var iframe = document.querySelector("iframe");
+iframe._onload_ = () => {
+    if (window.testRunner)
+        testRunner.notifyDone();
+};
+iframe.src = ""
+</script>
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (276985 => 276986)


--- trunk/Source/WebCore/ChangeLog	2021-05-04 22:29:04 UTC (rev 276985)
+++ trunk/Source/WebCore/ChangeLog	2021-05-04 22:37:08 UTC (rev 276986)
@@ -1,3 +1,19 @@
+2021-05-04  Chris Dumez  <cdu...@apple.com>
+
+        Blob contentType with charset renders html as plain text
+        https://bugs.webkit.org/show_bug.cgi?id=225226
+
+        Reviewed by Alex Christensen.
+
+        Our code would use the Blob's Content-Type (media type) as a MIME type internally. As a result, if the Blob's
+        media type would contain anything besides the MIME type (e.g. a charget), then it would lead to failures.
+
+        Test: fast/files/blob-with-charget-as-main-resource.html
+
+        * platform/network/BlobResourceHandle.cpp:
+        (WebCore::BlobResourceHandle::notifyResponseOnSuccess):
+        * platform/network/HTTPParsers.h:
+
 2021-05-04  Cameron McCormack  <hey...@apple.com>
 
         Handle clamping of heights for images affected by background-size and EXIF orientation correctly

Modified: trunk/Source/WebCore/platform/network/BlobResourceHandle.cpp (276985 => 276986)


--- trunk/Source/WebCore/platform/network/BlobResourceHandle.cpp	2021-05-04 22:29:04 UTC (rev 276985)
+++ trunk/Source/WebCore/platform/network/BlobResourceHandle.cpp	2021-05-04 22:37:08 UTC (rev 276986)
@@ -569,7 +569,7 @@
     ASSERT(isMainThread());
 
     bool isRangeRequest = m_rangeOffset != kPositionNotSpecified;
-    ResourceResponse response(firstRequest().url(), m_blobData->contentType(), m_totalRemainingSize, String());
+    ResourceResponse response(firstRequest().url(), extractMIMETypeFromMediaType(m_blobData->contentType()), m_totalRemainingSize, String());
     response.setHTTPStatusCode(isRangeRequest ? httpPartialContent : httpOK);
     response.setHTTPStatusText(isRangeRequest ? httpPartialContentText : httpOKText);
 

Modified: trunk/Source/WebCore/platform/network/HTTPParsers.h (276985 => 276986)


--- trunk/Source/WebCore/platform/network/HTTPParsers.h	2021-05-04 22:29:04 UTC (rev 276985)
+++ trunk/Source/WebCore/platform/network/HTTPParsers.h	2021-05-04 22:37:08 UTC (rev 276986)
@@ -79,7 +79,7 @@
 bool isValidHTTPToken(StringView);
 Optional<WallTime> parseHTTPDate(const String&);
 String filenameFromHTTPContentDisposition(const String&);
-String extractMIMETypeFromMediaType(const String&);
+WEBCORE_EXPORT String extractMIMETypeFromMediaType(const String&);
 String extractCharsetFromMediaType(const String&);
 XSSProtectionDisposition parseXSSProtectionHeader(const String& header, String& failureReason, unsigned& failurePosition, String& reportURL);
 AtomString extractReasonPhraseFromHTTPStatusLine(const String&);

Modified: trunk/Source/WebKit/ChangeLog (276985 => 276986)


--- trunk/Source/WebKit/ChangeLog	2021-05-04 22:29:04 UTC (rev 276985)
+++ trunk/Source/WebKit/ChangeLog	2021-05-04 22:37:08 UTC (rev 276986)
@@ -1,3 +1,16 @@
+2021-05-04  Chris Dumez  <cdu...@apple.com>
+
+        Blob contentType with charset renders html as plain text
+        https://bugs.webkit.org/show_bug.cgi?id=225226
+
+        Reviewed by Alex Christensen.
+
+        Our code would use the Blob's Content-Type (media type) as a MIME type internally. As a result, if the Blob's
+        media type would contain anything besides the MIME type (e.g. a charget), then it would lead to failures. 
+
+        * NetworkProcess/NetworkDataTaskBlob.cpp:
+        (WebKit::NetworkDataTaskBlob::dispatchDidReceiveResponse):
+
 2021-05-04  Alex Christensen  <achristen...@webkit.org>
 
         localStorage changes aren't reflected between WKWebViews using WKWebViewConfiguration._groupIdentifier

Modified: trunk/Source/WebKit/NetworkProcess/NetworkDataTaskBlob.cpp (276985 => 276986)


--- trunk/Source/WebKit/NetworkProcess/NetworkDataTaskBlob.cpp	2021-05-04 22:29:04 UTC (rev 276985)
+++ trunk/Source/WebKit/NetworkProcess/NetworkDataTaskBlob.cpp	2021-05-04 22:37:08 UTC (rev 276986)
@@ -255,7 +255,7 @@
     LOG(NetworkSession, "%p - NetworkDataTaskBlob::dispatchDidReceiveResponse(%u)", this, static_cast<unsigned>(errorCode));
 
     Ref<NetworkDataTaskBlob> protectedThis(*this);
-    ResourceResponse response(m_firstRequest.url(), errorCode != Error::NoError ? "text/plain" : m_blobData->contentType(), errorCode != Error::NoError ? 0 : m_totalRemainingSize, String());
+    ResourceResponse response(m_firstRequest.url(), errorCode != Error::NoError ? "text/plain" : extractMIMETypeFromMediaType(m_blobData->contentType()), errorCode != Error::NoError ? 0 : m_totalRemainingSize, String());
     switch (errorCode) {
     case Error::NoError: {
         bool isRangeRequest = m_rangeOffset != kPositionNotSpecified;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to