Bug 197369 - JSON displayed with wrong encoding when loaded in a frame (browser default instead of UTF-8)
Summary: JSON displayed with wrong encoding when loaded in a frame (browser default in...
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: Safari Technology Preview
Hardware: iPhone / iPad iOS 12
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
: 251871 (view as bug list)
Depends on:
Blocks:
 
Reported: 2019-04-29 08:55 PDT by Sébastien Deleuze
Modified: 2023-02-08 19:32 PST (History)
7 users (show)

See Also:


Attachments
Requesting directly an application/json endpoint (172.49 KB, image/jpeg)
2019-04-29 12:16 PDT, Sébastien Deleuze
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Sébastien Deleuze 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.
Comment 1 Sébastien Deleuze 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".
Comment 2 Alexey Proskuryakov 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>
Comment 3 Sébastien Deleuze 2019-04-29 12:16:19 PDT
Created attachment 368473 [details]
Requesting directly an application/json endpoint
Comment 4 Sébastien Deleuze 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.
Comment 5 Myles C. Maxfield 2021-02-03 11:33:49 PST
<rdar://problem/71522231>
Comment 6 Alexey Proskuryakov 2023-02-08 19:32:14 PST
*** Bug 251871 has been marked as a duplicate of this bug. ***