public
Last active

YAML modifies strings when it serializes them. What the crap?

  • Download Gist
output
1 2 3 4 5 6
$ ruby --version
ruby 1.9.2p136 (2010-12-25 revision 30365) [x86_64-darwin10.5.0]
$ ruby yaml_bug.rb
YAML modifies strings when it serializes them!
Original: "1\n \n2"
Modified: "1\n\n2"
yaml_bug.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12
require 'yaml'
 
string = "1\n \n2"
modified_string = YAML.load(string.to_yaml)
 
if string == modified_string
puts "YAML does not modify strings when it serializes them."
else
puts "YAML modifies strings when it serializes them!"
puts "Original: #{string.inspect}"
puts "Modified: #{modified_string.inspect}"
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.