diff options
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | dir.c | 8 | ||||
-rw-r--r-- | error.c | 10 | ||||
-rw-r--r-- | test/ruby/test_dir_m17n.rb | 11 | ||||
-rw-r--r-- | test/ruby/test_io_m17n.rb | 11 |
5 files changed, 38 insertions, 9 deletions
@@ -1,3 +1,10 @@ +Sat Feb 25 07:53:40 2012 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * dir.c (dir_initialize): keep path in original encoding. + + * error.c (syserr_initialize): prefer the encoding of message over + locale. [ruby-dev:45279][Bug #6071] + Sat Feb 25 06:55:29 2012 Nobuyoshi Nakada <nobu@ruby-lang.org> * file.c (utime_internal): fix a variable missed to replace. @@ -384,7 +384,7 @@ dir_initialize(int argc, VALUE *argv, VALUE dir) { struct dir_data *dp; rb_encoding *fsenc; - VALUE dirname, opt; + VALUE dirname, opt, orig; static VALUE sym_enc; if (!sym_enc) { @@ -402,7 +402,9 @@ dir_initialize(int argc, VALUE *argv, VALUE dir) } GlobPathValue(dirname, FALSE); + orig = rb_str_dup_frozen(dirname); dirname = rb_str_encode_ospath(dirname); + dirname = rb_str_dup_frozen(dirname); TypedData_Get_Struct(dir, struct dir_data, &dir_data_type, dp); if (dp->dir) closedir(dp->dir); @@ -416,10 +418,10 @@ dir_initialize(int argc, VALUE *argv, VALUE dir) dp->dir = opendir(RSTRING_PTR(dirname)); } if (dp->dir == NULL) { - rb_sys_fail_path(dirname); + rb_sys_fail_path(orig); } } - dp->path = rb_str_dup_frozen(dirname); + dp->path = orig; return dir; } @@ -1212,15 +1212,13 @@ syserr_initialize(int argc, VALUE *argv, VALUE self) else err = "unknown error"; if (!NIL_P(mesg)) { rb_encoding *le = rb_locale_encoding(); - VALUE str = mesg; + VALUE str = StringValue(mesg); + rb_encoding *me = rb_enc_get(mesg); - StringValue(str); mesg = rb_sprintf("%s - %.*s", err, (int)RSTRING_LEN(str), RSTRING_PTR(str)); - if (le == rb_usascii_encoding()) { - rb_encoding *me = rb_enc_get(mesg); - if (le != me && rb_enc_asciicompat(me)) - le = me; + if (le != me && rb_enc_asciicompat(me)) { + le = me; }/* else assume err is non ASCII string. */ OBJ_INFECT(mesg, str); rb_enc_associate(mesg, le); diff --git a/test/ruby/test_dir_m17n.rb b/test/ruby/test_dir_m17n.rb index 6701e0b1a5..1f5b03a905 100644 --- a/test/ruby/test_dir_m17n.rb +++ b/test/ruby/test_dir_m17n.rb @@ -213,5 +213,16 @@ class TestDir_M17N < Test::Unit::TestCase EOS } end + + def test_error_nonascii + bug6071 = '[ruby-dev:45279]' + paths = ["\u{3042}".encode("sjis"), "\u{ff}".encode("iso-8859-1")] + encs = with_tmpdir { + paths.map {|path| + Dir.open(path) rescue $!.message.encoding + } + } + assert_equal(paths.map(&:encoding), encs, bug6071) + end end diff --git a/test/ruby/test_io_m17n.rb b/test/ruby/test_io_m17n.rb index 737fae479b..02e60fb62f 100644 --- a/test/ruby/test_io_m17n.rb +++ b/test/ruby/test_io_m17n.rb @@ -2356,4 +2356,15 @@ EOT end } end if /mswin|mingw/ =~ RUBY_PLATFORM + + def test_error_nonascii + bug6071 = '[ruby-dev:45279]' + paths = ["\u{3042}".encode("sjis"), "\u{ff}".encode("iso-8859-1")] + encs = with_tmpdir { + paths.map {|path| + open(path) rescue $!.message.encoding + } + } + assert_equal(paths.map(&:encoding), encs, bug6071) + end end |