Last active
December 11, 2015 12:18
-
-
Save agile/4599353 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
irb> RUBY_VERSION | |
=> "1.9.3" | |
# it's 1.9.3-p374 if you wanna get picky.. | |
> JSON::VERSION | |
=> "1.5.4" | |
# So I have some json, from the body of a RestClient response that looks something like this: | |
irb> json = "{\"name\":\"Centrale Laiti\\u00e8re\"}" | |
=> "{\"name\":\"Centrale Laiti\\u00e8re\"}" | |
# This is what I'm expecting that name to look like.. | |
irb> expecting = "Centrale Laiti\u00e8re" | |
=> "Centrale Laitière" | |
irb> json.encoding | |
=> #<Encoding:UTF-8> | |
irb> expecting.encoding | |
=> #<Encoding:UTF-8> | |
# Seems reasonable, right? | |
irb> got = JSON.parse(json) | |
=> {"name"=>"Centrale Laitière"} | |
# Yea, it does.. | |
# SO.. here comes the WTF.. :) | |
bundle exec rails c | |
Loading development environment (Rails 3.2.11) | |
> JSON::VERSION | |
=> "1.5.4" | |
irb> json = "{\"name\":\"Centrale Laiti\\u00e8re\"}" | |
=> "{\"name\":\"Centrale Laiti\\u00e8re\"}" | |
# This is what I'm expecting that name to look like.. | |
irb> expecting = "Centrale Laiti\u00e8re" | |
=> "Centrale Laitière" | |
irb> json.encoding | |
=> #<Encoding:UTF-8> | |
irb> expecting.encoding | |
=> #<Encoding:UTF-8> | |
irb> require 'json' | |
=> false | |
irb> wtf = JSON.parse(json) | |
=> {"name"=>"Centrale LaitiX\xCDre"} | |
# whiskey-tango-foxtrot, over? | |
# Ah, seems to be a buggy JSON version.. the current rev seems to work correctly (within rails) | |
Loading development environment (Rails 3.2.11) | |
irb(main):001:0> json = "{\"name\":\"Centrale Laiti\\u00e8re\"}" | |
=> "{\"name\":\"Centrale Laiti\\u00e8re\"}" | |
irb(main):002:0> wtf = JSON.parse(json) | |
=> {"name"=>"Centrale Laitière"} | |
irb(main):003:0> JSON::VERSION | |
=> "1.7.6" | |
irb(main):004:0> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment