Feature #4224

inconsistent behavior of 'puts "\xFF"'

Added by Heesob Park almost 6 years ago. Updated over 5 years ago.



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
from -e:1:in puts'
from -e:1:in

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

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

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
+++ 2010-12-28 14:00:18.000000000 +0900
@@ -5312,7 +5312,7 @@
!rb_econv_has_convpath_p(rb_enc_name(rb_enc_get(str)), "UTF-16LE"))
return -1L;

  • str = rb_str_encode(str, rb_enc_from_encoding(rb_enc_find("UTF-16LE")), 0,
  • str = rb_str_encode(str, rb_enc_from_encoding(rb_enc_find("UTF-16LE")), ECONV_INVALID_REPLACE|ECONV_UNDEF_REPLACE, Qnil); if (!WriteConsoleW(handle, (LPWSTR)RSTRING_PTR(str), RSTRING_LEN(str)/2, &reslen, NULL)) { =end


#1 Updated by Yui NARUSE almost 6 years ago

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

"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.

#2 Updated by Yui NARUSE almost 6 years ago

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

#3 Updated by Yui NARUSE almost 6 years ago

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

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.


Also available in: Atom PDF