ActiveSupport's JSON decoder is incorrect.

http://dev.rubyonrails.org/ticket/9990 and reiterated here:

The current ActiveSupport JSON decoder uses YAML.load to parse json documents, and YAML has different escaping rules from JSON. In particular, in JSON, forward-slashes must be escaped (I'm not sure why, it isn't neccessary for Javascript, but thats the spec.) This presents problems for URLs in ActiveSupport JSON:

input = {"href" => "http://test.host/posts/1"\}

=> {"href"=>"http://test.host/posts/1"\}

json = ActiveSupport::JSON.encode(input)

=> "{"href":"http:\\/\\/test.host\\/posts\\/1"}"

output = ActiveSupport::JSON.decode(json)

=> {"href"=>"http:\\/\\/test.host\\/posts\\/1"}

input == output

=> false

I would expect that decode(encode(foo)) to return the exact same thing.

From the json gem:

json = JSON.unparse(input)

=> "{"href":"http:\\/\\/test.host\\/posts\\/1"}"

output = JSON.parse(json)

=> {"href"=>"http://test.host/posts/1"\}

input == output

=> true

There are tests in ActiveSupport, but the source strings are invalid JSON. Attached to the ticket is a patch that fixes the tests so that they fail, as they should. As for what to do to fix the problem, the core team will have to decide. Probably the best solution would be to include the relevant parts of the json gem as part of rails.

Thanks, Paul Sadauskas