Project

General

Profile

Actions

Bug #3180

closed

getc with text mode breaks incomplete character immediately before EOF

Added by mame (Yusuke Endoh) about 12 years ago. Updated about 11 years ago.

Status:
Closed
Priority:
Normal
Target version:
ruby -v:
ruby 1.9.2dev (2010-04-20 trunk 27405) [i686-linux]
Backport:
[ruby-dev:41024]

Description

=begin
遠藤です。

coding: UTF-8

"う" の途中で切れた中途半端なファイルを作る

s = "あいうえお".force_encoding("ASCII-8BIT")
open("foo.txt", "wb") {|f| f.write(s[0, 8]) }

IO#read で一気に読めば期待通り

open("foo.txt", "rt") {|f| p f.read } #=> "あい\xE3\x81"

UTF-8 を明示すると UTF-8 になるが、最後の文字が化ける

open("foo.txt", "rt:UTF-8") {|f| p f.chars.to_a }
#=> ["あ", "い", "\u0000\u0000"]

LANG は ja_JP.UTF-8 です。

incomplete な文字が "\0\0" に化けるのは意図的でしょうか。
期待としては、["あ", "い", "\xE3", "\x81"] です。

--
Yusuke Endoh
=end

Actions #1

Updated by naruse (Yui NARUSE) about 12 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

=begin
This issue was solved with changeset r27432.
Yusuke, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.

=end

Actions

Also available in: Atom PDF