{"action":"created","issue":{"url":"https://api.github.com/repos/ably/ably-js/issues/118","labels_url":"https://api.github.com/repos/ably/ably-js/issues/118/labels{/name}","comments_url":"https://api.github.com/repos/ably/ably-js/issues/118/comments","events_url":"https://api.github.com/repos/ably/ably-js/issues/118/events","html_url":"https://github.com/ably/ably-js/pull/118","id":104792010,"number":118,"title":"'utf-8' encoding currently assumes a wordArray?","user":{"login":"SimonWoolf","id":5908687,"avatar_url":"https://avatars.githubusercontent.com/u/5908687?v=3","gravatar_id":"","url":"https://api.github.com/users/SimonWoolf","html_url":"https://github.com/SimonWoolf","followers_url":"https://api.github.com/users/SimonWoolf/followers","following_url":"https://api.github.com/users/SimonWoolf/following{/other_user}","gists_url":"https://api.github.com/users/SimonWoolf/gists{/gist_id}","starred_url":"https://api.github.com/users/SimonWoolf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SimonWoolf/subscriptions","organizations_url":"https://api.github.com/users/SimonWoolf/orgs","repos_url":"https://api.github.com/users/SimonWoolf/repos","events_url":"https://api.github.com/users/SimonWoolf/events{/privacy}","received_events_url":"https://api.github.com/users/SimonWoolf/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":12,"created_at":"2015-09-03T22:16:10Z","updated_at":"2015-09-04T16:47:30Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/ably/ably-js/pulls/118","html_url":"https://github.com/ably/ably-js/pull/118","diff_url":"https://github.com/ably/ably-js/pull/118.diff","patch_url":"https://github.com/ably/ably-js/pull/118.patch"},"body":"So currently, if ably-js is fed a message like [this one](https://github.com/ably/ably-common/blob/master/test-resources/test-app-setup.json#L21) (not encrypted, but with a `utf-8` encoding), it feeds it to `BufferUtils.utf8Decode` because of the `utf-8` in the encoding, which in a browser, passes it to `CryptoJS.enc.Utf8.stringify`, which [expects](https://code.google.com/p/crypto-js/#Encoders) a wordArray so outputs an empty string. (in node it just calls `toString('utf-8')`, which works fine).\r\n\r\nThis PR fixes that immediate problem, but I'm not sure if there's a deeper issue here - not clear to me if there's a significant difference in how the different libs interpret `utf-8` (ably-js [treating it](https://github.com/ably/ably-js/blob/master/browser/lib/util/bufferutils.js) as meaning wordArray-encoded, ably-ruby [treating it](https://github.com/ably/ably-ruby/blob/master/lib/ably/models/message_encoders/utf8.rb) as meaning just a utf-8-encoded string), or if I'm misunderstanding the code\r\n\r\n@mattheworiordan @paddybyers "},"comment":{"url":"https://api.github.com/repos/ably/ably-js/issues/comments/137788343","html_url":"https://github.com/ably/ably-js/pull/118#issuecomment-137788343","issue_url":"https://api.github.com/repos/ably/ably-js/issues/118","id":137788343,"user":{"login":"paddybyers","id":1137574,"avatar_url":"https://avatars.githubusercontent.com/u/1137574?v=3","gravatar_id":"","url":"https://api.github.com/users/paddybyers","html_url":"https://github.com/paddybyers","followers_url":"https://api.github.com/users/paddybyers/followers","following_url":"https://api.github.com/users/paddybyers/following{/other_user}","gists_url":"https://api.github.com/users/paddybyers/gists{/gist_id}","starred_url":"https://api.github.com/users/paddybyers/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/paddybyers/subscriptions","organizations_url":"https://api.github.com/users/paddybyers/orgs","repos_url":"https://api.github.com/users/paddybyers/repos","events_url":"https://api.github.com/users/paddybyers/events{/privacy}","received_events_url":"https://api.github.com/users/paddybyers/received_events","type":"User","site_admin":false},"created_at":"2015-09-04T16:47:30Z","updated_at":"2015-09-04T16:47:30Z","body":"We have a valid reason for admitting both camel case and snake case - because of implementation convenience in different languages.\r\n\r\nThis case is different because there is no valid reason for any library to send an `encoding` string that doesn't correspond to the type of `data`.\r\n\r\nAccording to our spec, when decoding a received message, if any component of the `encoding` string cannot be reversed, the `data` is left unchanged at that point, and that `data` and the residual `encoding` string are returned to the client. We don't say that the encoding step is simply discarded because of a mismatch between the expected and actual types.\r\n\r\nIn the case of a message whose data is a String, the `utf-8` component of the encoding can't be \"unapplied\" because that only applies to binary data. So according to our spec we should return the String and the encoding with the `utf-8` component still present, and not apply any further decoding steps."}}