I have another tiny CSV file (UTF-16LE),
and also a tiny script reading it with the help of csv.rb.
require 'csv'
# $ $HOME/.rvm/bin/ruby-1.9.2-p180 -w test-utf.00.rb
# $ $HOME/.rvm/bin/jruby-head --1.9 -w test-utf.00.rb
f = open('g.UTF-16LE.csv', "r:UTF-16LE:UTF-8")
STDERR.printf("=%d: %s=>{%s},%s=>{%s} // %s\n",__LINE__,
'f.external_encoding',f.external_encoding,
'f.internal_encoding',f.internal_encoding,
'...')
f.read(2) # read off the BOM
CSV.new(f,headers: true, row_sep: "\r\n").each do |csv_record|
printf "%s=>{%05.5d},{%s}=>{%s}\n",
'$.',$.,
'f1',csv_record['f1']
end
It runs through just as expected with ruby-1.9.2-p180,
but it runs into an exception with jruby-head :
$ ~/.rvm/bin/jruby-head --version
jruby 1.6.0.RC2 (ruby 1.8.7 patchlevel 330) (2011-03-02 7fd4e3f)
(OpenJDK Server VM 1.6.0_20) [linux-i386-java]
$ ~/.rvm/bin/jruby-head --1.9 -w test-utf.00.rb
=8: f.external_encoding=>{UTF-16LE},f.internal_encoding=>{UTF-8} //
…
Encoding::CompatibilityError: incompatible encoding regexp match
(US-ASCII regexp with UTF-16LE string)
sub! at org/jruby/RubyString.java:2582
shift at
/home/jochen_hayek/.rvm/rubies/jruby-head/lib/ruby/1.9/csv.rb:1831
loop at org/jruby/RubyKernel.java:1417
shift at
/home/jochen_hayek/.rvm/rubies/jruby-head/lib/ruby/1.9/csv.rb:1825
each at
/home/jochen_hayek/.rvm/rubies/jruby-head/lib/ruby/1.9/csv.rb:1767
(root) at test-utf.00.rb:15
As before:
I talked to csv.rb’s developer and maintainer,
he also thinks, jruby (–1.9) needs fixing, not csv.rb.
J.