Commit a53ff8d6 authored by Marijn Kruisselbrink's avatar Marijn Kruisselbrink Committed by Commit Bot

[FileAPI] Properly set charset when loading blob URL.

Bug: 1086845
Change-Id: I1630dcff89198ea968ff49ff353d793ae19c10b3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2253242
Commit-Queue: Marijn Kruisselbrink <mek@chromium.org>
Reviewed-by: default avatarMason Freed <masonfreed@chromium.org>
Cr-Commit-Position: refs/heads/master@{#780118}
parent e48d0a02
......@@ -212,10 +212,10 @@ void BlobURLLoader::HeadersCompleted(
std::string mime_type;
response->headers->GetMimeType(&mime_type);
// Match logic in StreamURLRequestJob::HeadersCompleted.
if (mime_type.empty())
mime_type = "text/plain";
response->mime_type = mime_type;
response->headers->GetCharset(&response->charset);
// TODO(jam): some of this code can be shared with
// services/network/url_loader.h
......
async_test(t => {
const blob = new Blob(
[
`aaa\u001B$@<textarea>\u001B(B<script>/* xss */<\/script></textarea>bbb`
],
{type: 'text/html;charset=utf-8'});
const url = URL.createObjectURL(blob);
const win = window.open(url);
t.add_cleanup(() => win.close());
win.onload = t.step_func_done(() => {
assert_equals(win.document.charset, 'UTF-8');
});
}, 'Blob charset should override any auto-detected charset.');
async_test(t => {
const blob = new Blob(
[`<!doctype html>\n<meta charset="ISO-8859-1">`],
{type: 'text/html;charset=utf-8'});
const url = URL.createObjectURL(blob);
const win = window.open(url);
t.add_cleanup(() => win.close());
win.onload = t.step_func_done(() => {
assert_equals(win.document.charset, 'UTF-8');
});
}, 'Blob charset should override <meta charset>.');
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment