Skip to content

Commit

Permalink
fix #getc to handle encodings properly; passes chars_spec
Browse files Browse the repository at this point in the history
  • Loading branch information
chuckremes committed Jan 20, 2015
1 parent 94704d8 commit 4fb420e
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions kernel/common/io.rb
Expand Up @@ -1499,9 +1499,20 @@ def getbyte
# f.getc #=> 104
def getc
ensure_open
return if eof?

str = read(1)
return str
char = ""
until eof?
char.force_encoding Encoding::ASCII_8BIT
char << read(1)

char.force_encoding(self.external_encoding || Encoding.default_external)
if char.chr_at(0)
return IO.read_encode self, char
end
end

return nil
end

def gets(sep_or_limit=$/, limit=nil)
Expand Down

0 comments on commit 4fb420e

Please sign in to comment.