Bill Kelly
12/11/2005 2:10:00 AM
From: "Tom Payne" <ruby@tompayne.org>
>
> YAML.load("abc\r\n".to_yaml) # => "abc\n" ("\r" lost)
> YAML.load("\r\n".to_yaml) # => "" ("\r\n" lost)
> YAML.load("\n".to_yaml) # => "" ("\n" lost)
>
> My question is: how can I configure YAML to preserve my line endings?
> I'm using Ruby 1.8.4-preview2 and have Googled for a solution without
> success. Note that the :UseBlock option to to_yaml does not help.
On my system, ruby 1.8.2 (2004-12-25) [i386-mswin32], the first two
seemed to work:
>> YAML.load("abc\r\n".to_yaml)
=> "abc\r\n"
>> YAML.load("\r\n".to_yaml)
=> "\r\n"
But the third didn't:
>> YAML.load("\n".to_yaml)
=> " "
I guess if all else fails you could:
>> CGI.unescape(YAML.load(CGI.escape("\n").to_yaml))
=> "\n"
Regards,
Bill