Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

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

#4824

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"

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

State: duplicate
Milestone: none
Assigned to: José Valim José Valim
Importance: Low

Activity

  1. Rohit Arondekar
    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 \""
    

    June 13th, 2010 @ 10:44 AM

  2. José Valim
    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.

    June 13th, 2010 @ 10:47 AM

  3. Rohit Arondekar
    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?

    June 14th, 2010 @ 04:01 AM

  4. Maxime RETY
    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)

    June 14th, 2010 @ 04:10 PM

  5. Jeremy Kemper
    Jeremy Kemper
    • State changed from new to duplicate

    June 14th, 2010 @ 05:54 PM

  6. Jeff Kreeftmeijer
    Jeff Kreeftmeijer
    • Tag cleared.
    • Importance changed from to Low

    Automatic cleanup of spam.

    November 8th, 2010 @ 08:49 AM