String.encode functions differently to MRI when :universal_newline is passed
jamesrwhite opened this issue · 1 comments
jamesrwhite commented
Calling String.encode with :universal_newline => true doesn't seem to do anything, it should normalise line endings from what I understand.
Reproduction example:
james at air in ~
» cat string.rb
p "Hello\r\nWorld".encode(:universal_newline => true)
james at air in ~
» rvm use 2.1
Using /Users/james/.rvm/gems/ruby-2.1.0
james at air in ~
» ruby -v
ruby 2.1.0p0 (2013-12-25 revision 44422) [x86_64-darwin12.0]
james at air in ~
» ruby string.rb
"Hello\nWorld"
james at air in ~
» rvm use rbx-2.2.4
Using /Users/james/.rvm/gems/rbx-2.2.4
james at air in ~
» ruby -v
rubinius 2.2.4 (2.1.0 fd07f670 2014-02-01 JI) [x86_64-darwin13.0.0]
james at air in ~
» ruby string.rb
"Hello\r\nWorld"
OS:
» uname -a
Darwin air.local 13.0.0 Darwin Kernel Version 13.0.0: Thu Sep 19 22:22:27 PDT 2013; root:xnu-2422.1.72~6/RELEASE_X86_64 x86_64
aka OSX 10.9.1
I could be misunderstanding something but this seems like a bug to me. Let me know if you need any more info :)
jamesrwhite commented
This still doesn't work on rubinius 2.2.6 (2.1.0 68d916a5 2014-03-10 JI) [x86_64-darwin13.1.0]
but I was able to just replace it with
string.gsub(/\r\n?/, "\n")
for my use case if anyone stumbles across this same issue.