[Webkit-unassigned] [Bug 251871] New: JSON isn't implicitly treated as UTF-8
bugzilla-daemon at webkit.org
bugzilla-daemon at webkit.org
Tue Feb 7 11:30:54 PST 2023
https://bugs.webkit.org/show_bug.cgi?id=251871
Bug ID: 251871
Summary: JSON isn't implicitly treated as UTF-8
Product: WebKit
Version: Safari 16
Hardware: All
OS: All
Status: NEW
Severity: Normal
Priority: P2
Component: Layout and Rendering
Assignee: webkit-unassigned at lists.webkit.org
Reporter: webkit at aaroncarson.co.uk
CC: bfulgham at webkit.org, simon.fraser at apple.com,
zalan at apple.com
Created attachment 464889
--> https://bugs.webkit.org/attachment.cgi?id=464889&action=review
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
--
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-unassigned/attachments/20230207/41ab35f5/attachment.htm>
More information about the webkit-unassigned
mailing list