Project

General

Profile

Actions

Bug #8342

closed

IO.readlines ignores Encoding.default_internal if Encoding.default_external is ASCII-8BIT

Added by leocassarani (Leo Cassarani) over 11 years ago. Updated over 11 years ago.

Status:
Closed
Target version:
ruby -v:
1.9.3
[ruby-core:54656]

Description

Under normal circumstances, IO.readlines will transcode from Encoding.default_external to Encoding.default_internal:

File.open('hi', 'w') { |f| f.puts "hello\n" }
Encoding.default_external = Encoding::US_ASCII
Encoding.default_internal = Encoding::UTF_8
puts IO.readlines('hi').first.encoding
#=> UTF-8

However, when Encoding.default_external is set to ASCII-8BIT, IO.readlines will always use ASCII-8BIT, regardless of what Encoding.default_internal is set to:

File.open('hi', 'w') { |f| f.puts "hello\n" }
Encoding.default_external = Encoding::ASCII_8BIT
Encoding.default_internal = Encoding::UTF_8
puts IO.readlines('hi').first.encoding
#=> ASCII-8BIT

Using IO#gets instead of IO.readlines will produce the same behaviour.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0