Bug 197369

Summary: JSON displayed with wrong encoding when loaded in a frame (browser default instead of UTF-8)
Product: WebKit Reporter: Sébastien Deleuze <sdeleuze>
Component: New BugsAssignee: Nobody <webkit-unassigned>
Status: NEW ---    
Severity: Normal CC: ap, beidson, keith_miller, mmaxfield, saam, webkit, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: Safari Technology Preview   
Hardware: iPhone / iPad   
OS: iOS 12   
See Also: https://bugs.webkit.org/show_bug.cgi?id=66056
Description Flags
Requesting directly an application/json endpoint none

Description Sébastien Deleuze 2019-04-29 08:55:20 PDT

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">
var x = new XMLHttpRequest;
x.open("GET", "http://thax.hardliners.org/issue438464.php?json=1");
x.onload = function() { alert(x.response); }
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
Comment 6 Alexey Proskuryakov 2023-02-08 19:32:14 PST
*** Bug 251871 has been marked as a duplicate of this bug. ***