Details
-
Type:
Bug
-
Status:
Resolved
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: JRuby 1.6.6, JRuby 1.6.7
-
Fix Version/s: JRuby 1.7.0.pre1
-
Component/s: Core Classes/Modules, Ruby 1.9.2
-
Environment:2.6.18-274.12.1.el5.centos
-
Number of attachments :
Description
If I set Encoding.default_internal to 'utf-8', I can't read binary from file even I open file with the 'b' option.
The File.gets always return a string encoding with "Encoding.default_internal".
I think this maybe an Encoding problem.
See the script:
def to_hex(str) s = "" str.bytes.each { |b| s += b.to_s(16) } return s end def show File.open('zh_cn-utf8.txt', 'rb') do |file| line = file.gets puts "line: #{line}" puts "!!!to_hex(line): #{to_hex(line)}" puts "!!!line.encoding.name: #{line.encoding.name}" puts "!!!Encoding.default_internal: #{Encoding.default_internal}" end endThere is the output(notice the hex, utf-8 encoding for '中' is 'e4b8ada'!!!):
<<<Encoding.default_external = nil line: 中 {color:red}!!!to_hex(line): e4b8ada !!!line.encoding.name: ASCII-8BIT{color} !!!Encoding.default_internal: ---------------------------- <<<Encoding.default_external = "utf8" line: 中 {color:red}!!!to_hex(line): c3a4c2b8c2ada !!!line.encoding.name: UTF-8{color} !!!Encoding.default_internal: UTF-8