Feature #4224

inconsistent behavior of 'puts "\xFF"'

Added by Heesob Park over 3 years ago. Updated almost 3 years ago.

[ruby-core:33999]
Status:Closed
Priority:Normal
Assignee:Usaku NAKAMURA
Category:core
Target version:1.9.3

Description

=begin
C:\work>ruby -ve 'puts "\xFFabc"'
ruby 1.9.3dev (2010-12-28 trunk 30412) [i386-mswin32_90]
-e:1:in write': "\xFF" on CP949 (Encoding::InvalidByteSequenceError)
from -e:1:in
puts'
from -e:1:in puts'
from -e:1:in
'

$ ruby -ve 'puts "\xFFabc"'
ruby 1.9.3dev (2010-12-02) [i686-linux]
abc

C:>ruby -ve 'puts "\xFFabc"'
ruby 1.9.2p136 (2010-12-25) [i386-mingw32]
abc

The trunk version raises Encoding::InvalidByteSequenceError on Windows.
But, on the other version and other platform, it works without error.
What is the proper behavior?

I think this error could be avoided by following patch:

--- win32.c 2010-12-28 13:59:30.000000000 +0900
+++ win32.c.new 2010-12-28 14:00:18.000000000 +0900
@@ -5312,7 +5312,7 @@
!rbeconvhasconvpathp(rbencname(rbencget(str)), "UTF-16LE"))
return -1L;

  • str = rbstrencode(str, rbencfromencoding(rbenc_find("UTF-16LE")), 0,
  • str = rbstrencode(str, rbencfromencoding(rbencfind("UTF-16LE")), ECONVINVALIDREPLACE|ECONVUNDEFREPLACE, Qnil); if (!WriteConsoleW(handle, (LPWSTR)RSTRINGPTR(str), RSTRING_LEN(str)/2, &reslen, NULL)) { =end

History

#1 Updated by Yui NARUSE over 3 years ago

  • Status changed from Open to Assigned
  • Assignee set to Usaku NAKAMURA

=begin
"Current spec" seems:
* if external encoding is set, output may raise exception
* if not set, output won't raise exception

Because this case is latter even if ruby converts strings internally,
it shouldn't raise exception.

Anyway in this case specifically, \xFF should be converted to U+F8F7.
So this is conversion table's bug.
http://icu-project.org/repos/icu/data/trunk/charset/data/ucm/windows-949-2000.ucm
=end

#2 Updated by Yui NARUSE over 3 years ago

=begin
After further thought, current conversion table is correct.
And your patch is the correct way.
=end

#3 Updated by Yui NARUSE over 3 years ago

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

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

=end

Also available in: Atom PDF