This project is archived and is in readonly mode.
String.to_json creates invalid JSON
-
Josh Kalderimis
- Importance changed from to Low
Hi Paul,
I have tested this myself and can't seem to replicate the issue, are you able to create a failing test case to confirm the issue.
Thanks,
J
-
Paul Alexander
Sure...but I' not sure how to prep one. I have my own application with specs and tests and I can repeatedly produce this result...is there a standard way of submitting a complete reproduction test?
-
Paul Alexander
...worked out a sample
rails new sample
cd sample
rails console
'"'.to_json # => ""\""" '"'.to_json == '"' # => false
-
Paul Alexander
Sorry...forgot this was markdown
# rails new sample # cd sample # rails console> '"'.to_json # => "\"\\\"\"" > '"'.to_json == '\"' # => false -
Paul Alexander
Rechecking my logic
'"'.to_jsonshould =='"\""'. Not sure where the "e; thing is coming from. Must be from another gem. -
Josh Kalderimis
- State changed from new to invalid
Hi Paul,
I am closing this issue as invalid as I can not replicate it. I think the problem you are having is that you are relying on the console output and not
puts. The console/irb uses inspect whileputswill escape things correctly. eg.'"'.to_json => "\"\\\"\"" puts '"'.to_json "\""I have tested encoding and decoding strings using ActiveSupport::JSON and Yajl separately but both work perfectly.
s = 'here is a famous quote : "I got 99 problems but my json aint one"' => "here is a famous quote : \"I got 99 problems but my json aint one\"" puts s here is a famous quote : "I got 99 problems but my json aint one" json = Yajl::Encoder.encode s => "\"here is a famous quote : \\\"I got 99 problems but my json aint one\\\"\"" puts json "here is a famous quote : \"I got 99 problems but my json aint one\"" Yajl::Parser.parse json => "here is a famous quote : \"I got 99 problems but my json aint one\"" puts Yajl::Parser.parse json here is a famous quote : "I got 99 problems but my json aint one"Please reopen this ticket if you can replicate the issue in a failing testcase.
Thanks,
Josh