This project is archived and is in readonly mode.
ActiveSupport::JSON.decode seems to remove newlines and multiple spaces
-
Rohit Arondekar
- Assigned user set to José Valim
Note: That JSON string gives an error. I've included the corrected string in the samples below.
Confirmed on Rails master and 1.9.2-head.
Does not happen on 1.8.7-p174.ruby-1.9.2-head > ActiveSupport::JSON.decode("data=\"\u000a function(){\u000a var a = 1;\u000a }\u000a\u000a \"") #=> "data=\" function(){ var a = 1; }\n\""ruby-1.8.7-p174 > ActiveSupport::JSON.decode("data=\"\u000a function(){\u000a var a = 1;\u000a }\u000a\u000a \"") => "data=\"u000a function(){u000a var a = 1;u000a }u000au000a \"" -
José Valim
Rails just delegates to the JSON library. So it's more likely the JSON library changed its behavior from 1.8.7 to 1.9.2 version. Please do investigate.
-
Rohit Arondekar
I think my comparison examples are wrong. In Ruby 1.8.7, \u000a are not recognized as unicode chars.
ruby-1.8.7-p174 > "\u000a" => "u000a"Whereas in Ruby 1.9.2 they are:
ruby-1.9.2-head > "\u000a" => "\n"Now if I replace \u000a with \n the behavior is consistent.
ruby-1.9.2-head > ActiveSupport::JSON.decode("data=\"\n function(){\n var a = 1;\n }\n\n \"") => "data=\" function(){ var a = 1; }\n\""ruby-1.8.7-p174 > ActiveSupport::JSON.decode("data=\"\n function(){\n var a = 1;\n }\n\n \"") => "data=\" function(){ var a = 1; }\n\""Correct me if I'm wrong, but either this is not an issue or it's a problem with json. Maybe creating an issue here http://github.com/flori/json/issues would be helpful?
-
Maxime RETY
This JSON-decoding bug seems to be the same as a previously reported bug :
https://rails.lighthouseapp.com/projects/8994/tickets/3479-activesu...I just added a comment to ticket 3479 with a patch proposal.
(note : this bug is related to the use of YAML backend to decode JSON. It doesn't seem specific to any rails or ruby version)