# API: goal resource escapes unicode in "title"

**URL:** <https://forum.beeminder.com/t/api-goal-resource-escapes-unicode-in-title/5111>\
**Category:** Bugabee\
**Created:** [March 15, 2019, 1:35pm UTC](https://forum.beeminder.com/t/api-goal-resource-escapes-unicode-in-title/5111 "2019-03-15T13:35:47Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![phi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.beeminder.com/phi/32/2586_2.png) [@phi](https://forum.beeminder.com/u/phi)\
**Post date:** [March 15, 2019, 1:35pm UTC](https://forum.beeminder.com/t/api-goal-resource-escapes-unicode-in-title/5111/1 "2019-03-15T13:35:47Z")

</div>

```http
GET https://www.beeminder.com/api/v1/users/me/goals/water.json?auth_token=nononogofetchyourown HTTP/1.0

```

gives:

```json
{
  "slug": "water",
  "title": "\u0026 Co.",

```

That’s a `& Co.`.

whereas the `"delta_text"` of:

```http
GET https://www.beeminder.com/api/v1/users/me/goals/workout.json?auth_token=nononogofetchyourown HTTP/1.0

```

right now is:

```json
  "delta_text": "✔ +0 +0.43",

```

Here’s what the RFC says about this: [https://tools.ietf.org/html/rfc7159#section-7](https://tools.ietf.org/html/rfc7159#section-7)

I found this working on the dashboard. The json library I use choked on the title and reports the above as

```json
{
  "slug": "water",
  "title": null
}

```

and ends the json document there. To me that looks like a bug on the library’s side. The RFC does explicitly say characters MAY be escaped.  
Still, I’m reporting this here because I think the escaping in the title is unintended given that a) it needs no escaping and b) other attributes are not escaped either.  
I entered the title via the website in top part of the goal page:  
 ![image](https://us1.discourse-cdn.com/flex019/uploads/beeminder/original/2X/2/232da7e10133dffbd2aa24efb8437351d945a29b.png)

And by “title” I mean… [description](https://forum.beeminder.com/t/complice-should-show-goalnames-not-just-descriptions/5068/5?u=phi)?

---

<div class="post-metadata">

**Author:** ![bee](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.beeminder.com/bee/32/41_2.png) [@bee](https://forum.beeminder.com/u/bee)\
**Post date:** [March 19, 2019, 2:36am UTC](https://forum.beeminder.com/t/api-goal-resource-escapes-unicode-in-title/5111/2 "2019-03-19T02:36:53Z")

</div>

Taking a look at what’s stored in the database, we’re storing the unicode un-escaped, and the api is not explicitly escaping things. I just ran a test with one of my own things, and other unicode characters are fine, but when I copy in the description from your water goal, it’s giving the escaped unicode with curl, and showing up unescaped in other libraries… so something with the json parsing / library on the other end perhaps?

Here’s what I see via curl  
`"ϡ and ⎈ ⏰ ◒ \u0026 and hurray!"`

and via my ruby library of choice  
`"ϡ and ⎈ ⏰ ◒ & and hurray!"`

---

<div class="post-metadata">

**Author:** ![phi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.beeminder.com/phi/32/2586_2.png) [@phi](https://forum.beeminder.com/u/phi)\
**Post date:** [March 19, 2019, 9:38am UTC](https://forum.beeminder.com/t/api-goal-resource-escapes-unicode-in-title/5111/3 "2019-03-19T09:38:34Z")

</div>

Here’s my working theory:

1. The API sends out `ϡ and ⎈ ⏰ ◒ \u0026 and hurray!`
2. That’s what curl receives and that’s what the library I am using receives
3. Your ruby library of choice then goes ahead and unescapes the `\u0026` again before giving it to you
4. The lib I’m using recently added a [flag](https://arduinojson.org/v6/api/config/decode_unicode) to control this behaviour. It is disabled by default because it puts additional strain on the already tiny processor in an Arduino, I assume. Using this flag the `\u0026` does get translated back to `&` just as it should and the library does not choke on it.

I wouldn’t know why the API sends out the ampersand escaped but I have a suspicion which I hope is wrong: It might be that they think they do you a “favour” by escaping the oh-so-dangerous ampersand so it doesn’t to funny things in your HTML by accident. I hope I’m wrong 😉

---

<div class="post-metadata">

**Author:** ![bee](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.beeminder.com/bee/32/41_2.png) [@bee](https://forum.beeminder.com/u/bee)\
**Post date:** [March 19, 2019, 11:56pm UTC](https://forum.beeminder.com/t/api-goal-resource-escapes-unicode-in-title/5111/4 "2019-03-19T23:56:19Z")

</div>

> [@phi](#):
>
> It might be that they think they do you a “favour” by escaping the oh-so-dangerous ampersand

Ah, I suppose that’s probably it. Anyhow, you’re correct; I was looking in slightly the wrong place previously, and yes, Beeminder’s JSON library is “helpfully” escaping just-that-one unicode character.

I guess that means “It is the opinion of this Authoritative Source [i.e. a widely used JSON gem that’s probably the default thing that most Rails use], that escaping ampersands is the Correct Behavior”, in which case, I’m loath to change that default behavior without good reason.

---

<div class="post-metadata">

**Author:** ![phi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.beeminder.com/phi/32/2586_2.png) [@phi](https://forum.beeminder.com/u/phi)\
**Post date:** [March 20, 2019, 12:58am UTC](https://forum.beeminder.com/t/api-goal-resource-escapes-unicode-in-title/5111/5 "2019-03-20T00:58:47Z")

</div>

Totally agree. Either way, there is no “wrong” behaviour here as far as I see. It’s technically correct to escape all characters inside a JSON string as far as the RFC is concerned. If that’s desired or not is of course a different and subjective question 😉 One that ultimately depends on the… wait for it… character. 🙈 😛
