Skip to content

Instantly share code, notes, and snippets.

@Quintus
Created February 21, 2013 16:42
Show Gist options
  • Save Quintus/5006071 to your computer and use it in GitHub Desktop.
Save Quintus/5006071 to your computer and use it in GitHub Desktop.
# jruby 1.7.2 (1.9.3p327) 2013-01-04 302c706 on Java HotSpot(TM) 64-Bit Server VM 1.7.0_13-b20 [linux-amd64]
[12] pry(main)> str = "AA\xC3AA"
=> "AA\xC3AA"
[13] pry(main)> str.encoding
=> #<Encoding:UTF-8>
[14] pry(main)> str.force_encoding("BINARY")
=> "AA\xC3AA"
[15] pry(main)> str.encode("UTF-8")
Encoding::UndefinedConversionError: "\xC3" from ASCII-8BIT to UTF-8
from org/jruby/RubyString.java:7563:in `encode'
[16] pry(main)> str.encode("UTF-8", :undef => :replace)
Encoding::UndefinedConversionError: "\xC3" from ASCII-8BIT to UTF-8 #<== Diese Exception darf nicht sein
# ruby 1.9.3p385 (2013-02-06 revision 39114) [x86_64-linux]
1] pry(main)> str = "AA\xC3AA"
=> "AA\xC3AA"
[2] pry(main)> str.force_encoding("BINARY")
=> "AA\xC3AA"
[3] pry(main)> str.encode("UTF-8")
Encoding::UndefinedConversionError: "\xC3" from ASCII-8BIT to UTF-8
from (pry):3:in `encode'
[4] pry(main)> str.encode("UTF-8", :undef => :replace)
=> "AA?AA" #<== Das ist das korrekte Ergebnis
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment