nomad-cli / houston

Apple Push Notifications; No Dirigible Required
http://nomad-cli.com
MIT License
2.93k stars 229 forks source link

Fix Emoji when used with ActiveSupport::JSON #147

Closed msroot closed 7 years ago

msroot commented 7 years ago

When i use houston with ActiveSupport the ActiveSupport::JSON to_json will overwrite the JSON's to_jsonmethod and Emojis doent display right

example with ActiveSupport::JSON:


[2] pry(main)> defined?(ActiveSupport::JSON) 
=> "constant"

[1] pry(main)> "💬".to_json
=> "\"\\uf4ac\""

example with JSON:


2.1.6 :003 > "💬".to_json
 => "\"💬\""
dankimio commented 7 years ago

Thank you for the pull request! What version of ActiveSupport are you using? Does that problem exist in later Ruby versions?

msroot commented 7 years ago

Hi I am using activesupport 3.2.22.5

json = MultiJson.dump(payload)
[2, json.bytes.count, json].pack('cna*')

=> "\x02\x00o{\"aps\":{\"alert\":\"Workin? ---> \xF0\x9F\x92\xAC \xE2\x9D\xA4\xEF\xB8\x8F \xF0\x9F\x8E\xB6 \xF0\x9F\x8E\xB6 \xF0\x9F\x8E\xB6\",\"badge\":0,\"content-available\":1,\"mutable-content\":1}}"
json = payload.to_json
[2, json.bytes.count, json].pack('cna*')
=> "\x02\x00}{\"aps\":{\"alert\":\"Workin? ---> \\uf4ac \\u2764\\ufe0f \\uf3b6 \\uf3b6 \\uf3b6\",\"badge\":0,\"content-available\":1,\"mutable-content\":1}}"
dankimio commented 7 years ago

@msroot Can you upgrade your app to Rails 4.2 or 5 (and Ruby 2.2 or later)? That issue should have been fixed in those versions of ActiveSupport. Rails 3 is no longer maintained and there aren't any goals to support it in houston. And I also think that this is not the responsibility of the gem to take care of all possible overrides by other libraries.

This is the output from ActiveSupport 5.0.2:

>> "💬".to_json
=> "\"💬\""