WebKit Bugzilla
New
Browse
Search+
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
RESOLVED DUPLICATE of
bug 197369
251871
JSON isn't implicitly treated as UTF-8
https://bugs.webkit.org/show_bug.cgi?id=251871
Summary
JSON isn't implicitly treated as UTF-8
Aaron Carson
Reported
2023-02-07 11:30:54 PST
Created
attachment 464889
[details]
Screenshot demonstrating Safari's behaviour with and without ;charset=utf-8 Hi! According to section 8 of RFC 8259[1], all JSON documents must be encoded using UTF-8 / Unicode. If a JSON file is accessed directly within Safari (for example, an API endpoint is accessed), it uses the browser's default encoding (for me, it defaulted to `Western (ISO Latin 1)` to render it. This can lead to garbled text; I discovered this as an API endpoint I created contains two emoji characters which did not render correctly within Safari. In Chrome, it renders fine. If the `Content-Type` HTTP header is set to `application/json;charset=utf-8`, it works fine in Safari. However, the inclusion of this is widely discouraged[2][3]. Not only that, IANA specifically call out that there is no `charset` parameter defined for the `application/json` media type[4]. So WebKit should automatically assume that `application/json` is in UTF-8 and render it as such. Otherwise, there will be more people who fall down a rabbit hole trying to work out what they've done wrong with character encoding when writing an API endpoint whilst using Safari! [1]
https://datatracker.ietf.org/doc/html/rfc8259#section-8
[2]
https://github.com/request/request/issues/383
[3]
https://stackoverflow.com/questions/70250068/with-fastapi-how-to-add-charset-to-content-type-media-type-on-request-header#:~:text=Short%20answer,not%20be%20necessary
. [4]
https://www.iana.org/assignments/media-types/application/json
Attachments
Screenshot demonstrating Safari's behaviour with and without ;charset=utf-8
(717.44 KB, image/png)
2023-02-07 11:30 PST
,
Aaron Carson
no flags
Details
View All
Add attachment
proposed patch, testcase, etc.
Aaron Carson
Comment 1
2023-02-07 11:34:05 PST
I may have misread #197369 as being about how JSON is processed in XMLHTTPRequests and/or iFrames but it seems it is a duplicate to a degree. Will leave as is currently though so maintainers can assess whether they're different at all.
Alexey Proskuryakov
Comment 2
2023-02-08 19:32:14 PST
I think that it's an exact duplicate. *** This bug has been marked as a duplicate of
bug 197369
***
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug