Skip to content

Instantly share code, notes, and snippets.

@myronmarston
Created February 8, 2011 02:47
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save myronmarston/815754 to your computer and use it in GitHub Desktop.
YAML modifies strings when it serializes them. What the crap?
$ 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"
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment