NEW 197369
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
Summary JSON displayed with wrong encoding when loaded in a frame (browser default in...
Sébastien Deleuze
Reported 2019-04-29 08:55:20 PDT
Hey, I am one of the committer of Spring Framework working on our web support (Spring MVC) and we would like to stop specifying artificially UTF-8 charset for JSON (with "application/json;charset=utf-8", see https://github.com/spring-projects/spring-framework/issues/22788 for more details) since per spec "application/json" does not support charset parameter (https://tools.ietf.org/html/rfc7159#section-11) and UTF-8 should be used by default (https://tools.ietf.org/html/rfc8259#section-8.1). This very annoying bug has been fixed in September 2017 in Chrome (see https://bugs.chromium.org/p/chromium/issues/detail?id=438464) and Firefox renders as well correctly special characters with "application/json" so Safari is the last big player to not handling that correctly. To reproduce the bug, as described in the Chrome issue please compare rendering of http://thax.hardliners.org/issue438464.php?json=1 with Firefox, Chrome and Safari. Firefox and Safari render correctly the special characters while Safari does not. Thanks in advance for your help on this issue.
Attachments
Requesting directly an application/json endpoint (172.49 KB, image/jpeg)
2019-04-29 12:16 PDT, Sébastien Deleuze
no flags
Sébastien Deleuze
Comment 1 2019-04-29 09:08:16 PDT
Small mistake in previous comment, you should read "Firefox and Chrome render correctly the special characters while Safari does not".
Alexey Proskuryakov
Comment 2 2019-04-29 10:59:29 PDT
In my testing, loading the link via XMLHttpRequest does default to application/json, it's only loading into mail frame that uses default encoding. Which is arguably inconsistent, but not very much so, as the content is handled as text/plain in this case. Is loading JSON into the main frame something that Spring MVC does? Or is there some other scenario where a real website or framework is affected? <meta charset="windows-1251"> <script> var x = new XMLHttpRequest; x.open("GET", "http://thax.hardliners.org/issue438464.php?json=1"); x.onload = function() { alert(x.response); } x.send(); </script>
Sébastien Deleuze
Comment 3 2019-04-29 12:16:19 PDT
Created attachment 368473 [details] Requesting directly an application/json endpoint
Sébastien Deleuze
Comment 4 2019-04-29 12:24:51 PDT
Happy to hear that the main use case (XMLHttpRequest) is working correctly, that will allow us to move forward and switch back on "application/json". Thanks for checking. My laptop is under Linux so I used Safari on my iPhone to test and when I request directly an "application/json" endpoint, broken encoding is displayed as shown in the attached screenshot. Same endpoint with "application/json;charset=utf-8" is displayed correctly in the main frame. That's said, current behavior is likely to be confusing for a lot of web developers and is not consistent ("application/json;charset=utf-8" is displayed correctly), so I hope it will be fixed in a future release of Safari.
Myles C. Maxfield
Comment 5 2021-02-03 11:33:49 PST
Alexey Proskuryakov
Comment 6 2023-02-08 19:32:14 PST
*** Bug 251871 has been marked as a duplicate of this bug. ***
Alexey Proskuryakov
Comment 7 2025-04-21 16:45:35 PDT
*** Bug 291833 has been marked as a duplicate of this bug. ***
Note You need to log in before you can comment on or make changes to this bug.