This project is archived and is in readonly mode.
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
-
Daniel Sheppard September 5th, 2008 @ 03:07 AM
Bah, wasn't expecting markdown.
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":"\\","trailing":""} 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":"\\x","trailing":""} p ActiveSupport::JSON.decode(string) #=> {"good"=>"\\x", "trailing"=>""} string = "{\"good\":\"\\\\\"}" puts string #=> {"good":"\\"} p ActiveSupport::JSON.decode(string) #=> {"good"=>"\\"}
-
Daniel Sheppard September 5th, 2008 @ 03:37 AM
- Title changed from JSON parser fails to read escaped backslashes to [PATCH] JSON parser fails to read escaped backslashes
- Tag changed from activesupport to activesupport, patch, tested
Stringscanner was thinking that it was still within quotes due to treating the second slash as an escape character. Patch fixes.
-
bmulloy December 1st, 2008 @ 04:42 AM
with this patch it seems that \ becomes .
\ -> \ (1 stays as 1) \ -> \ (2 becomes 1) \\ -> \ (3 becomes 2) \\ -> \ (4 becomes 2)
-
Pratik December 22nd, 2008 @ 02:37 PM
- Title changed from [PATCH] JSON parser fails to read escaped backslashes to JSON parser fails to read escaped backslashes
Removing '[PATCH]' prefix
-
Pratik March 8th, 2009 @ 01:51 PM
- Assigned user set to Pratik
- State changed from new to incomplete
I can't apply the patch anymore. Could you please upload a new patch using git-format-patch ? http://guides.rails.info/contrib... should be helpful.
Thanks !
-
Daniel Sheppard March 9th, 2009 @ 11:11 PM
I don't have an edge environment around
It's literally a three line change (including tests) - Can't you just read the patch and replay?
-
CancelProfileIsBroken August 5th, 2009 @ 03:25 PM
- Tag changed from activesupport, patch, tested to activesupport, bugmash, patch, tested
-
Nikolay Petrachkov August 8th, 2009 @ 12:44 PM
Verified problem that described above.
I've attached a patch. That is fixed patch by Daniel Sheppard.
-
Nikolay Petrachkov August 9th, 2009 @ 08:34 AM
- Assigned user changed from Pratik to José Valim
and i've attached a patch for master. Previous one was for 2-3-stable.
-
Rizwan Reza August 9th, 2009 @ 04:11 PM
verified
+1 Both patches apply cleanly to the respective branches. All tests pass.
-
Repository August 10th, 2009 @ 06:32 AM
- State changed from incomplete to committed
(from [9341655fa30ffc245093493422c9abe72eeb64ed]) Fix that JSON parser fails to read escaped backslashes.
[#973 state:committed]
Signed-off-by: Jeremy Kemper jeremy@bitsweat.net
http://github.com/rails/rails/commit/9341655fa30ffc245093493422c9ab... -
Repository August 10th, 2009 @ 06:32 AM
(from [b3381cacaf7735ec6eb108e378ba255ebf6ffb14]) Fix that JSON parser fails to read escaped backslashes.
[#973 state:committed]
Signed-off-by: Jeremy Kemper jeremy@bitsweat.net
http://github.com/rails/rails/commit/b3381cacaf7735ec6eb108e378ba25... -
Jeremy Kemper August 10th, 2009 @ 06:32 AM
- Tag changed from activesupport, bugmash, patch, tested to activesupport, patch, tested
- Milestone changed from 2.x to 2.3.4
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>
People watching this ticket
Attachments
Tags
Referenced by
- 973 JSON parser fails to read escaped backslashes [#973 state:committed]
- 973 JSON parser fails to read escaped backslashes [#973 state:committed]
- 1100 JSON decoding of \u escape sequences #973 points out another JSON decoding issue. These two sh...