Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: JRuby 1.6.6
-
Fix Version/s: JRuby 1.6.7
-
Component/s: Ruby 1.9.2
-
Labels:None
-
Testcase included:yes
-
Number of attachments :
Description
# encoding: utf-8
require 'stringio'
str = %Q{?xml version="1.0" encoding="UTF-8" ?>
<xml><tag>—</tag></xml>}
io = StringIO.new(str)
str2 = io.readline
puts "Should be utf-8: #{str2.encoding}"
BELOW was originally reported issue in the context of how StringIO is used by Rexml...
arturas@arturaz-fujitsu:~/work/jruby/xmlbug$ JRUBY_OPTS="--1.9" rvm jruby-1.6.6,ruby-1.9.2,ruby-1.9.3 do ruby xmlbug.rb
Ruby: java, 1.9.2
Encoding::CompatibilityError: incompatible character encodings: UTF-8 and ASCII-8BIT
concat at org/jruby/RubyString.java:2499
to_s at /home/arturas/.rvm/rubies/jruby-1.6.6/lib/ruby/1.9/rexml/parseexception.rb:24
message at org/jruby/RubyException.java:245
Ruby: i686-linux, 1.9.2
Parsed OK.
Ruby: i686-linux, 1.9.3
Parsed OK.
Test case:
arturas@arturaz-fujitsu:~/work/jruby/xmlbug$ cat xmlbug.rb
# encoding: utf-8
puts
puts
puts "Ruby: #{RUBY_PLATFORM}, #{RUBY_VERSION}"
require 'rexml/document'
xml = %Q{?xml version="1.0" encoding="UTF-8" ?>
<xml><tag>į</tag></xml>}.force_encoding("UTF-8")
doc = REXML::Document.new(xml)
puts "Parsed OK."
I reduced this issue to something wrong with readline in StringIO. It may affect other methods in StringIO as well.