Skip to content

Instantly share code, notes, and snippets.

@chuckremes
Last active August 29, 2015 14:14
Show Gist options
  • Save chuckremes/317ad32a6ac4f6fb6d1b to your computer and use it in GitHub Desktop.
Save chuckremes/317ad32a6ac4f6fb6d1b to your computer and use it in GitHub Desktop.
When running this spec, I get an encoding compatibility error:
https://github.com/rubinius/rubinius/blob/master/spec/ruby/core/io/gets_spec.rb#L280
results in:
1)
IO#gets transcodes into the IO object's internal encoding, when set ERROR
Encoding::CompatibilityError: undefined conversion for '"\u00FE\u00FF\u0000l\u0000i\u0000n\u0000e"' from UTF-16 to UTF-8
Rubinius::Type.compatible_encoding at kernel/common/type.rb:533
String#index at kernel/common/string.rb:2261
IO::EachReader#read_to_separator at kernel/common/io.rb:1008
IO::EachReader#each at kernel/common/io.rb:965
IO#each at kernel/common/io.rb:1251
IO#gets at kernel/common/io.rb:1494
{ } in Object#__script__ at spec/ruby/core/io/gets_copy_spec.rb:30
BasicObject(Object)#instance_eval at kernel/common/eval.rb:43
{ } in Enumerable(Array)#all? at kernel/common/enumerable.rb:329
Array#each at kernel/bootstrap/array.rb:76
Enumerable(Array)#all? at kernel/common/enumerable.rb:329
Integer(Fixnum)#times at kernel/common/integer.rb:196
Array#each at kernel/bootstrap/array.rb:76
Object#__script__ at spec/ruby/core/io/gets_copy_spec.rb:7
Kernel.load at kernel/common/kernel.rb:497
BasicObject(Object)#instance_eval at kernel/common/eval.rb:43
Array#each at kernel/bootstrap/array.rb:76
Rubinius::CodeLoader#load_script at kernel/delta/code_loader.rb:66
Rubinius::CodeLoader.load_script at kernel/delta/code_loader.rb:152
Rubinius::Loader#script at kernel/loader.rb:645
Rubinius::Loader#main at kernel/loader.rb:799
I can repro with this script:
```
Encoding.default_internal = Encoding::US_ASCII
string = "\u00FE\u00FF\u0000l\u0000i\u0000n\u0000e".force_encoding(Encoding::UTF_16)
string.index("\n")
```
which returns:
An exception occurred running index_spec.rb:
undefined conversion for '"\xC3\xBE\xC3\xBF\x00l\x00i\x00n\x00e"' from UTF-16 to UTF-8 (Encoding::CompatibilityError)
Backtrace:
Rubinius::Type.compatible_encoding at kernel/common/type.rb:533
String#index at kernel/common/string.rb:2261
Object#__script__ at index_spec.rb:4
Rubinius::CodeLoader#load_script at kernel/delta/code_loader.rb:66
Rubinius::CodeLoader.load_script at kernel/delta/code_loader.rb:152
Rubinius::Loader#script at kernel/loader.rb:645
Rubinius::Loader#main at kernel/loader.rb:799
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment