Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: 90c69edf1c0ebeef9a60ead6ad3e6cae9a19577a
https://github.com/WebKit/WebKit/commit/90c69edf1c0ebeef9a60ead6ad3e6cae9a19577a
Author: Chris Dumez <[email protected]>
Date: 2026-06-28 (Sun, 28 Jun 2026)
Changed paths:
A
LayoutTests/imported/w3c/web-platform-tests/FileAPI/reading-data-section/filereader_readAsText_blob_type_charset.any-expected.txt
A
LayoutTests/imported/w3c/web-platform-tests/FileAPI/reading-data-section/filereader_readAsText_blob_type_charset.any.html
A
LayoutTests/imported/w3c/web-platform-tests/FileAPI/reading-data-section/filereader_readAsText_blob_type_charset.any.js
A
LayoutTests/imported/w3c/web-platform-tests/FileAPI/reading-data-section/filereader_readAsText_blob_type_charset.any.worker-expected.txt
A
LayoutTests/imported/w3c/web-platform-tests/FileAPI/reading-data-section/filereader_readAsText_blob_type_charset.any.worker.html
M Source/WebCore/fileapi/FileReaderLoader.cpp
M Source/WebCore/fileapi/FileReaderSync.cpp
Log Message:
-----------
FileReader.readAsText() ignores the charset parameter of the Blob's type
https://bugs.webkit.org/show_bug.cgi?id=318003
Reviewed by Anne van Kesteren and Darin Adler.
Per the File API "read as text" algorithm, the text encoding is determined in
the following order of precedence:
1. the explicit `encoding` argument, if it is a supported encoding;
2. otherwise, the `charset` parameter of the Blob's `type`, if present;
3. otherwise, UTF-8.
See the "package data" steps (Text case) in the specification:
https://w3c.github.io/FileAPI/#blob-package-data
WebKit implemented steps (1) and (3) but skipped (2): convertToText() hard-coded
"text/plain" and only chose between the explicit encoding argument and UTF-8,
never consulting the Blob's type. As a result, reading a Blob whose type carries
a non-UTF-8 charset (e.g. `new Blob([bytes], { type:
"text/plain;charset=windows-1252" })`)
with `FileReader.readAsText(blob)` (no encoding argument) decoded the data as
UTF-8 instead of windows-1252, producing incorrect characters (U+FFFD).
This is a spec-conformance and interoperability bug: Firefox correctly honors
the
Blob type's charset, while WebKit and Chrome (which share the same
FileReaderLoader
heritage) both ignored it. This change brings WebKit in line with the
specification
and with Firefox. BOM detection continues to override the selected encoding,
and an
explicit encoding argument still takes precedence over the Blob type's charset.
FileReaderSync::readAsText() additionally never forwarded the Blob's type to the
loader, so the synchronous reader could not honor the charset either; it now
sets
the data type to match the asynchronous FileReader path.
Note that Blob.text() is unaffected and remains UTF-8-only as required by its
own
specification: it loads via BlobLoader, which never sets the loader's data
type, so
the charset fallback resolves to UTF-8.
Test:
imported/w3c/web-platform-tests/FileAPI/reading-data-section/filereader_readAsText_blob_type_charset.any.js
* Source/WebCore/fileapi/FileReaderLoader.cpp:
(WebCore::FileReaderLoader::convertToText): Fall back to the charset parameter
of
the Blob's type (m_dataType) when no valid explicit encoding was supplied,
before
defaulting to UTF-8.
* Source/WebCore/fileapi/FileReaderSync.cpp:
(WebCore::FileReaderSync::readAsText): Forward the Blob's type to the loader so
the
synchronous reader applies the same encoding-determination rules.
*
LayoutTests/imported/w3c/web-platform-tests/FileAPI/reading-data-section/filereader_readAsText_blob_type_charset.any.js:
Added.
*
LayoutTests/imported/w3c/web-platform-tests/FileAPI/reading-data-section/filereader_readAsText_blob_type_charset.any.html:
Added.
*
LayoutTests/imported/w3c/web-platform-tests/FileAPI/reading-data-section/filereader_readAsText_blob_type_charset.any.worker.html:
Added.
*
LayoutTests/imported/w3c/web-platform-tests/FileAPI/reading-data-section/filereader_readAsText_blob_type_charset.any-expected.txt:
Added.
*
LayoutTests/imported/w3c/web-platform-tests/FileAPI/reading-data-section/filereader_readAsText_blob_type_charset.any.worker-expected.txt:
Added.
Canonical link: https://commits.webkit.org/315996@main
To unsubscribe from these emails, change your notification settings at
https://github.com/WebKit/WebKit/settings/notifications