This project is archived and is in readonly mode.

#4824 ✓duplicate
teesea

ActiveSupport::JSON.decode seems to remove newlines and multiple spaces

Reported by teesea | June 10th, 2010 @ 03:47 PM

If you enter the following in the console you see that the multiple spaces and the new lines are removed

ActiveSupport::JSON.decode("data="\u000a function(){\u000a var a = 1;\u000a }\u000a\u000a "")
=> data=" function(){ var a = 1; }\n"

Comments and changes to this ticket

  • Rohit Arondekar

    Rohit Arondekar June 13th, 2010 @ 10:44 AM

    • 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

    José Valim June 13th, 2010 @ 10:47 AM

    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

    Rohit Arondekar June 14th, 2010 @ 04:01 AM

    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

    Maxime RETY June 14th, 2010 @ 04:10 PM

    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)

  • Jeremy Kemper

    Jeremy Kemper June 14th, 2010 @ 05:54 PM

    • State changed from “new” to “duplicate”
  • Jeff Kreeftmeijer

    Jeff Kreeftmeijer November 8th, 2010 @ 08:49 AM

    • Tag cleared.
    • Importance changed from “” to “Low”

    Automatic cleanup of spam.

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>

Pages