Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

String.encode functions differently to MRI when :universal_newline is passed #2944

Closed
jamesrwhite opened this Issue · 1 comment

2 participants

@jamesrwhite

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

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.

@jamesrwhite jamesrwhite referenced this issue in jamesrwhite/minicron
Open

Get minicron running on rbx (rubinius) #76

@jamesrwhite jamesrwhite referenced this issue from a commit in jamesrwhite/minicron
@jamesrwhite jamesrwhite String encoding doesn't work correctly on rbx (rubinius/rubinius#2944)…
… so trying to replace it with this instead #76
451db5a
@jamesrwhite jamesrwhite referenced this issue from a commit in jamesrwhite/minicron
@jamesrwhite jamesrwhite Merge branch 'master' of github.com:jamesrwhite/minicron
# By James White (5) and Cyril Bouthors (2)
* 'master' of github.com:jamesrwhite/minicron:
  Updates for JRuby/RBX support
  These changes also seem to be needed #76
  String encoding doesn't work correctly on rbx (rubinius/rubinius#2944) so trying to replace it with this instead #76
  * lib/minicron/transport/faye/extensions/job_handler.rb: typo
  * README.md: fixed typo
  Add 'Credit'
  Update README.md
6e68176
@YorickPeterse YorickPeterse closed this issue from a commit
@YorickPeterse YorickPeterse Support for String#encode with :universal_newline.
This has been implemented directly in String#encode similar to the :xml option.
I'm not sure if this is the best place to put it in but I can't find a better
alternative.

This fixes #2944.
00ca75e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.