Skip to content

Instantly share code, notes, and snippets.

@denisdefreyne
Created September 4, 2013 21:11
Show Gist options
  • Save denisdefreyne/6442942 to your computer and use it in GitHub Desktop.
Save denisdefreyne/6442942 to your computer and use it in GitHub Desktop.
UTF-8 case that crashes in MRI and does not crash in Rubinius
# encoding: utf-8
File.write('foo.txt', 'Hëllö'.encode('ISO-8859-1'))
data = File.binread('foo.txt')
data.force_encoding('utf-8')
data.encode!('utf-8')
data.gsub!("\xEF\xBB\xBF", '')
# Crashes in Ruby 1.9.3p392:
#
# test.rb:8:in `gsub!': invalid byte sequence in UTF-8 (ArgumentError)
# from test.rb:8:in `<main>'
#
# Does not crash in Rubinius
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment