to_json clobbers emoji
benhamill opened this issue Β· 1 comments
benhamill commented
The JsonGem
adapter uses JsonCommon
, which called to_json
in it's dump
method. I recently discovered that this causes problems marshalling and unmarshalling emoji.
Behold:
2.2.5 :024 > x
=> {:message=>"π©π©βπ€ππͺππππ³ππππππ\u{1F921}πβΊοΈπ£πΏπ"}
2.2.5 :025 > MultiJson.adapter
=> MultiJson::Adapters::JsonGem
2.2.5 :026 > MultiJson.dump(x)
=> "{\"message\":\"\\uf469\\u200d\\uf3a4\\uf383\\uf62a\\uf614\\uf61f\\uf60d\\uf633\\uf60e\\uf64f\\uf600\\uf615\\uf600\\uf60f\\uf921\\uf590\\u263a\\ufe0f\\uf623\\uf47f\\uf60a\"}"
2.2.5 :027 > MultiJson.load(MultiJson.dump(x))
=> {"message"=>"ο©ο€οοͺοοοο³οοοοοοε΅οβΊοΈο£οΏο"}
I think this is just a one-line change in json_common.rb from to_json
to JSON.dump
. But maybe that's not true for all the things that use JsonCommon
? Is this a change y'all would be interested in seeing?
rwz commented
I can't recreate this bug:
[4] pry(main)> MultiJson.adapter
=> MultiJson::Adapters::JsonGem
[5] pry(main)> x = {:message=>"π©π©βπ€ππͺππππ³ππππππ\u{1F921}πβΊοΈπ£πΏπ"}
=> {:message=>"π©π©βπ€ππͺππππ³πππππππ€‘πβΊοΈπ£πΏπ"}
[6] pry(main)> MultiJson.dump(x)
=> "{\"message\":\"π©π©βπ€ππͺππππ³πππππππ€‘πβΊοΈπ£πΏπ\"}"
[7] pry(main)> MultiJson.load(MultiJson.dump(x))
=> {"message"=>"π©π©βπ€ππͺππππ³πππππππ€‘πβΊοΈπ£πΏπ"}
What version of json gem are you using? Does ugrading the gem solve the issue for you?