Topic: [Bug] API returning invalid characters/escape sequences

Posted under Site Bug Reports & Feature Requests

Bug overview description.
When comments are fetched through the JSON API, emojis are returned as invalid escape sequences which leads to characters like ๏˜. The codes are off by 0x10000. I fixed it in my code (JS) with this function.

const fixEmojis = text =>
      text.replace(/([\uf000-\uffff])/g, char =>
        String.fromCodePoint(char.codePointAt(0) + 0x10000)
      );

What part(s) of the site page(s) are affected?
JSON API

What is the expected behavior?
The JSON contains the emoji or the right escape sequence.

What actual behavior is given instead?
An invalid escape sequence is returned.

Time of incident (if applicable).
/

Can you reproduce the bug every time?
Yes

What steps did you take to replicate this bug?
View any comment with an emoji through the API. The JSON in this example has the invalid character \uf60d while the XML displays the correct emoji ๐Ÿ˜.

https://e621.net/comment/show.json?id=4107288

{"id":4107288,"created_at":"2018-10-07 01:59","post_id":1629018,"creator":"Talikk","creator_id":294704,"body":"Absolutely beautiful \uf60d the true vision of perfection!","score":1}

https://e621.net/comment/show.xml?id=4107288

<comment>
<id type="integer">4107288</id>
<created_at>2018-10-07 01:59</created_at>
<post_id type="integer">1629018</post_id>
<creator>Talikk</creator>
<creator_id type="integer">294704</creator_id>
<body>
Absolutely beautiful ๐Ÿ˜ the true vision of perfection!
</body>
<score type="integer">1</score>
</comment>

Errors or other messages returned (if any).
/

  • 1