This project is archived and is in readonly mode.
JSON parser fails to read escaped backslashes
-
Daniel Sheppard
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 stringThe 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
- 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
with this patch it seems that \ becomes .
\ -> \ (1 stays as 1) \ -> \ (2 becomes 1) \\ -> \ (3 becomes 2) \\ -> \ (4 becomes 2)
-
bmulloy
my bad. please ignore the above comment. the patch is fine.
-
Pratik
- Title changed from [PATCH] JSON parser fails to read escaped backslashes to JSON parser fails to read escaped backslashes
Removing '[PATCH]' prefix
-
Pratik
- 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
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
- Tag changed from activesupport, patch, tested to activesupport, bugmash, patch, tested
-
Nikolay Petrachkov
Verified problem that described above.
I've attached a patch. That is fixed patch by Daniel Sheppard.
-
Nikolay Petrachkov
- 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
verified
+1 Both patches apply cleanly to the respective branches. All tests pass.
-
Repository
- 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
(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
- Tag changed from activesupport, bugmash, patch, tested to activesupport, patch, tested
- Milestone changed from 2.x to 2.3.4
