Skip to content

Instantly share code, notes, and snippets.

@mvidner
Created October 16, 2012 11:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mvidner/3898842 to your computer and use it in GitHub Desktop.
Save mvidner/3898842 to your computer and use it in GitHub Desktop.
Ruby 1.9 encoding: "\xFF" is not binary
rbx-2.0.0-dev
Running with rubinius 2.0.0dev (1.9.3 9ad741f3 yyyy-mm-dd JI) [i686-pc-linux-gnu]
* A binary packet with 255.chr
ASCII-8BIT: � ("\xFF") 1 bytes
* A binary packet with "\xEE"
US-ASCII: � ("\xEE") 1 bytes
* Putting them together with String#+
An exception occurred running rbx-encoding-backslash-x.rb
undefined conversion for '"\xFF"' from ASCII-8BIT to US-ASCII (Rubinius::EncodingClass::Encoding::CompatibilityError)
Backtrace:
Rubinius::Type.compatible_encoding at kernel/common/type19.rb:47
String#<< at kernel/common/string19.rb:420
String#+ at kernel/common/string.rb:65
Object#__script__ at rbx-encoding-backslash-x.rb:21
Rubinius::CodeLoader#load_script at kernel/delta/codeloader.rb:68
Rubinius::CodeLoader.load_script at kernel/delta/codeloader.rb:110
Rubinius::Loader#script at kernel/loader.rb:614
Rubinius::Loader#main at kernel/loader.rb:815
1.9.3-p194
Running with ruby 1.9.3p194 (2012-04-20 revision 35410) [i686-linux]
* A binary packet with 255.chr
ASCII-8BIT: � ("\xFF") 1 bytes
* A binary packet with "\xEE"
ASCII-8BIT: � ("\xEE") 1 bytes
* Putting them together with String#+
ASCII-8BIT: �� ("\xFF\xEE") 2 bytes
jruby-1.6.7
Running with jruby 1.6.7 (ruby-1.9.2-p312) (2012-02-22 3e82bc8) (Java HotSpot(TM) Client VM 1.7.0_07) [linux-i386-java]
* A binary packet with 255.chr
ASCII-8BIT: � ("\u00FF") 1 bytes
* A binary packet with "\xEE"
ASCII-8BIT: � ("\u00EE") 1 bytes
* Putting them together with String#+
ASCII-8BIT: �� ("\u00FF\u00EE") 2 bytes
#! /usr/bin/env ruby
puts "Running with #{RUBY_DESCRIPTION}"
def dump(s)
puts "#{s.encoding}: #{s} (#{s.inspect}) #{s.bytesize} bytes"
end
puts '* A binary packet with 255.chr'
binchr = 255.chr
dump binchr
puts '* A binary packet with "\xEE"'
binhex = "\xEE"
# rbx-19mode has US-ASCII. other 1.9 rubies have ASCII-8BIT already
# Forcing 8 bit avoids the bug.
# binhex.force_encoding('ASCII-8BIT')
dump binhex
puts '* Putting them together with String#+'
together = binchr + binhex
dump together
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment