Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 70cd4be688bb80e05c128e6de6a7bcad7d62183a
      
https://github.com/WebKit/WebKit/commit/70cd4be688bb80e05c128e6de6a7bcad7d62183a
  Author: Ahmad Saleem <[email protected]>
  Date:   2026-09-06 (Sun, 06 Sep 2026)

  Changed paths:
    A 
LayoutTests/imported/w3c/web-platform-tests/encoding/json-document-utf8-expected.txt
    A 
LayoutTests/imported/w3c/web-platform-tests/encoding/json-document-utf8.html
    A 
LayoutTests/imported/w3c/web-platform-tests/encoding/resources/json-charset.py
    M Source/WebCore/loader/DocumentWriter.cpp
    M Source/WebCore/loader/TextResourceDecoder.cpp
    M Source/WebCore/loader/TextResourceDecoder.h

  Log Message:
  -----------
  JSON displayed with wrong encoding when loaded in a frame (browser default 
instead of UTF-8)
https://bugs.webkit.org/show_bug.cgi?id=197369
rdar://71522231

Reviewed by Chris Dumez.

The patch aligns WebKit with Gecko / Firefox and Blink / Chromium.

When an "application/json" response with no charset parameter was loaded into a
frame, WebCore rendered it as a text/plain document and decoded it using the
locale/default text encoding (or the parent frame's encoding), producing
mojibake for non-ASCII UTF-8 content. text/xml already defaulted to UTF-8, and
the XMLHttpRequest path already forced UTF-8, but the frame-display path did 
not.

Per RFC 8259 "The JavaScript Object Notation (JSON) Data Interchange Format",
section 8.1 "Character Encoding"
(https://www.rfc-editor.org/rfc/rfc8259#section-8.1):

    "JSON text exchanged between systems that are not part of a closed
     ecosystem MUST be encoded using UTF-8 [RFC3629]."

RFC 7159 section 8.1 states the default explicitly ("The default encoding is
UTF-8 ..."), and the "application/json" media type registration defines no
"charset" parameter.

Default JSON documents to UTF-8, matching the existing text/xml handling, while
still letting a BOM (for UTF-16) or an explicit charset parameter override it,
and stop JSON subframes from inheriting a non-UTF-8 same-origin parent frame's
encoding.

* Source/WebCore/loader/TextResourceDecoder.h:
Add JSON to the ContentType enum.

* Source/WebCore/loader/TextResourceDecoder.cpp:
(WebCore::TextResourceDecoder::determineContentType): Classify JSON MIME types
as JSON.
(WebCore::TextResourceDecoder::defaultEncoding): Default the JSON content type
to UTF-8, matching XML.

* Source/WebCore/loader/DocumentWriter.cpp:
(WebCore::DocumentWriter::decoder): Don't override a JSON document's UTF-8
default with a non-UTF-8 parent frame encoding.

* LayoutTests/imported/w3c/web-platform-tests/encoding/json-document-utf8.html: 
Added.
* 
LayoutTests/imported/w3c/web-platform-tests/encoding/json-document-utf8-expected.txt:
 Added.
* 
LayoutTests/imported/w3c/web-platform-tests/encoding/resources/json-charset.py: 
Added.

Canonical link: https://commits.webkit.org/320596@main



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications

Reply via email to