This project is archived and is in readonly mode.

#973 ✓committed
Daniel Sheppard

JSON parser fails to read escaped backslashes

Reported by Daniel Sheppard | September 5th, 2008 @ 03:03 AM | in 2.3.4

ActiveSupport::JSON cannot parse a string as a hash value that end with backslashes if there are subsequent values in the hash, ie:

string = "{[bad]("\\","trailing":""}") puts string

=> {bad

p ActiveSupport::JSON.decode(string)

=> ActiveSupport::JSON::ParseError: Invalid JSON string

The json gem parser works correctly:

require 'json' p JSON.parse(string)

=>{"bad"=>"\", "trailing"=>""}

There is no problem if the backslash is not the last character, or if there is no subsequent values in the hash:

string = "{[good]("\\x","trailing":""}") puts string

=> {good

p ActiveSupport::JSON.decode(string)

=> {"good"=>"\x", "trailing"=>""}

string = "{[good]("\\"}") puts string

=> {good

p ActiveSupport::JSON.decode(string)

=> {"good"=>"\"}

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Referenced by

Pages