Skip to content

Instantly share code, notes, and snippets.

@nick1123
Created April 19, 2013 15:17
Show Gist options
  • Save nick1123/5421037 to your computer and use it in GitHub Desktop.
Save nick1123/5421037 to your computer and use it in GitHub Desktop.
s = "hello\xdf".force_encoding("ASCII-8BIT")
s.encode("UTF-8", :invalid => :replace, :undef => :replace, :replace => "")
@spencerroan
Copy link

Encoding::UndefinedConversionError: "\xDF" from ASCII-8BIT to UTF-8
from org/jruby/RubyString.java:7580:in encode' from (irb):2:inevaluate'
from org/jruby/RubyKernel.java:1066:in eval' from org/jruby/RubyKernel.java:1392:inloop'
from org/jruby/RubyKernel.java:1174:in catch' from org/jruby/RubyKernel.java:1174:incatch'
from /Users/spencerroan/.rvm/rubies/jruby-1.7.2/bin/jirb:13:in `(root)'

@spencerroan
Copy link

java version "1.6.0_43"
Java(TM) SE Runtime Environment (build 1.6.0_43-b01-447-11M4203)
Java HotSpot(TM) 64-Bit Server VM (build 20.14-b01-447, mixed mode)

@spencerroan
Copy link

java -version

@spencerroan
Copy link

1.9.3p374 :001 > s = "hello\xdf".force_encoding("ASCII-8BIT") 
 => "hello\xDF" 
1.9.3p374 :002 > s.encode("UTF-8", :invalid => :replace, :undef => :replace, :replace => "")
 => "hello"  
1.9.3p374 :004 > RUBY_PLATFORM
 => "x86_64-darwin11.4.2" 
1.9.3p374 :005 > RUBY_VERSION
 => "1.9.3" 

you can see that it is patch 374.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment