Skip to content

Commit

Permalink
Charset of blobs are incorrectly ignored
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=243953

Reviewed by Geoffrey Garen.

We were failing to set the text encoding name on the ResourceResponse
based on the charset present in the Content-Type HTTP header.
Normally, it gets initialized lazily by ResourceResponse::textEncodingName()
based on the Content-Type header. However, this doesn't happen for Blobs
because there is no underlying NSURLRequest.

* LayoutTests/imported/w3c/web-platform-tests/FileAPI/url/url-charset.window-expected.txt:
* Source/WebCore/platform/network/BlobResourceHandle.cpp:
(WebCore::BlobResourceHandle::notifyResponseOnSuccess):
* Source/WebCore/platform/network/HTTPParsers.h:
* Source/WebKit/NetworkProcess/NetworkDataTaskBlob.cpp:
(WebKit::NetworkDataTaskBlob::dispatchDidReceiveResponse):

Canonical link: https://commits.webkit.org/253458@main
  • Loading branch information
cdumez committed Aug 16, 2022
1 parent b51ce8f commit 0f75f96
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 3 deletions.
@@ -1,4 +1,4 @@

FAIL Blob charset should override any auto-detected charset. assert_equals: expected "UTF-8" but got "windows-1252"
FAIL Blob charset should override <meta charset>. assert_equals: expected "UTF-8" but got "windows-1252"
PASS Blob charset should override any auto-detected charset.
PASS Blob charset should override <meta charset>.

1 change: 1 addition & 0 deletions Source/WebCore/platform/network/BlobResourceHandle.cpp
Expand Up @@ -575,6 +575,7 @@ void BlobResourceHandle::notifyResponseOnSuccess()
response.setHTTPStatusText(isRangeRequest ? httpPartialContentText : httpOKText);

response.setHTTPHeaderField(HTTPHeaderName::ContentType, m_blobData->contentType());
response.setTextEncodingName(extractCharsetFromMediaType(m_blobData->contentType()).toAtomString());
response.setHTTPHeaderField(HTTPHeaderName::ContentLength, String::number(m_totalRemainingSize));
addCrossOriginOpenerPolicyHeaders(response, m_blobData->policyContainer().crossOriginOpenerPolicy);
addCrossOriginEmbedderPolicyHeaders(response, m_blobData->policyContainer().crossOriginEmbedderPolicy);
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/platform/network/HTTPParsers.h
Expand Up @@ -81,7 +81,7 @@ bool isValidHTTPToken(StringView);
std::optional<WallTime> parseHTTPDate(const String&);
StringView filenameFromHTTPContentDisposition(StringView);
WEBCORE_EXPORT String extractMIMETypeFromMediaType(const String&);
StringView extractCharsetFromMediaType(StringView);
WEBCORE_EXPORT StringView extractCharsetFromMediaType(StringView);
XSSProtectionDisposition parseXSSProtectionHeader(const String& header, String& failureReason, unsigned& failurePosition, String& reportURL);
AtomString extractReasonPhraseFromHTTPStatusLine(const String&);
WEBCORE_EXPORT XFrameOptionsDisposition parseXFrameOptionsHeader(StringView);
Expand Down
1 change: 1 addition & 0 deletions Source/WebKit/NetworkProcess/NetworkDataTaskBlob.cpp
Expand Up @@ -266,6 +266,7 @@ void NetworkDataTaskBlob::dispatchDidReceiveResponse(Error errorCode)
response.setHTTPStatusText(isRangeRequest ? httpPartialContentText : httpOKText);

response.setHTTPHeaderField(HTTPHeaderName::ContentType, m_blobData->contentType());
response.setTextEncodingName(extractCharsetFromMediaType(m_blobData->contentType()).toAtomString());
response.setHTTPHeaderField(HTTPHeaderName::ContentLength, String::number(m_totalRemainingSize));
addCrossOriginOpenerPolicyHeaders(response, m_blobData->policyContainer().crossOriginOpenerPolicy);
addCrossOriginEmbedderPolicyHeaders(response, m_blobData->policyContainer().crossOriginEmbedderPolicy);
Expand Down

0 comments on commit 0f75f96

Please sign in to comment.