Incorrect encoding on JSONP API

Need the mods or admins to do something for you? Post here. Read the "About" post first.

Moderators: Moderators General, Prelates, Magistrates

Pishmoffle
Posts: 0
Joined: Wed Feb 24, 2016 10:51 am UTC
Location: Denmark

Incorrect encoding on JSONP API

Postby Pishmoffle » Wed Feb 24, 2016 11:04 am UTC

Today's comic (#1647) has revealed an encoding issue on the alt text of the JSONP-API, which I am using for an info-screen at our office. :)

(I cannot use the normal JSON API, since it doesn't set an Access-Control-Allow-Origin-header, and therefore cannot use it for cross-origin requests.)

Sadly I cannot link the APIs in question as that's considered spam by the forum software, but hopefully it's possible to deduce which APIs I'm talking about.

Pishmoffle
Posts: 0
Joined: Wed Feb 24, 2016 10:51 am UTC
Location: Denmark

Re: Incorrect encoding on JSONP API

Postby Pishmoffle » Wed Feb 24, 2016 11:21 am UTC

Hmm. Actually looking at the Access-Control-Allow-Origin header of the API I'm using, it appears to be internal. (Oh dear.)

In any case, the bug is still there, and it'd be lovely to get a Access-Control-Allow-Origin header on the normal JSON API, so that it can be used from AJAX calls. :)

User avatar
phlip
Restorer of Worlds
Posts: 7538
Joined: Sat Sep 23, 2006 3:56 am UTC
Location: Australia
Contact:

Re: Incorrect encoding on JSONP API

Postby phlip » Wed Feb 24, 2016 11:35 am UTC

To be specific, in the info.0.json for the strip, the word "forté" is encoded as "fort\u00c3\u00a9", which is definitely messed up.

[edit] And the transcript (which is, as separately noticed, in the json for 1649) is even worse:

Code: Select all

"transcript": "Typed letter: Attached please find my r\u00c3\u00a9s\u00c3\u00bcme[MANY STRANGE MARKINGS OVER AND BENEATH THIS LAST LETTER]\n\nI usually leave out diacritics when I type, so I make up for it by occasionally adding a whole bunch at once.\n\n{{Title text: Using diacritics correctly is not my fort\u00c3\u0083\u00c2\u00a9.}}"
Like... "r\u00c3\u00a9s\u00c3\u00bcme" is just more of the same, but "fort\u00c3\u0083\u00c2\u00a9" has somehow been double fucked. It's not even consistent within the same string.

And the JSONP goes one step further, encoding these Unicode characters again as direct UTF-8 (not \u escapes), and then serves it with no encoding tag in the content-type header, so the browser would need to guess it's UTF-8 just to not add yet another level of misencoding to the data. From my testing, it seems to depend on whether the HTML file that includes the JS file is UTF-8 encoded or not, which is madness, but that's the browser world for you... (you can get around this last hiccup by using <script charset="utf-8">, or by adding scriptCharset:'utf-8' to the $.ajax call if you're using jQuery).

Code: Select all

enum ಠ_ಠ {°□°╰=1, °Д°╰, ಠ益ಠ╰};
void ┻━┻︵​╰(ಠ_ಠ ⚠) {exit((int)⚠);}
[he/him/his]

Ajedi32
Posts: 0
Joined: Wed Jan 13, 2016 4:13 am UTC

Re: Incorrect encoding on JSONP API

Postby Ajedi32 » Sat Feb 27, 2016 6:56 pm UTC

Seconding the request for Access-Control-Allow-Origin. I've encountered the same problem: /viewtopic.php?f=10&t=113315

I didn't know there was a JSONP API. Where is that documented?

User avatar
phlip
Restorer of Worlds
Posts: 7538
Joined: Sat Sep 23, 2006 3:56 am UTC
Location: Australia
Contact:

Re: Incorrect encoding on JSONP API

Postby phlip » Mon Feb 29, 2016 3:56 am UTC

Code: Select all

enum ಠ_ಠ {°□°╰=1, °Д°╰, ಠ益ಠ╰};
void ┻━┻︵​╰(ಠ_ಠ ⚠) {exit((int)⚠);}
[he/him/his]

User avatar
PM 2Ring
Posts: 3615
Joined: Mon Jan 26, 2009 3:19 pm UTC
Location: Mid north coast, NSW, Australia

Re: Incorrect encoding on JSONP API

Postby PM 2Ring » Fri Apr 14, 2017 4:52 pm UTC

It's still there. In https://xkcd.com/1824/info.0.json we have

Code: Select all

alt": "Be careful—it's breeding season, and some of these can be *extremely* defensive of their nests.",


BTW, this bug was mentioned on Stack Overflow Meta.


Return to “Site/Forum issues”

Who is online

Users browsing this forum: No registered users and 7 guests