1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34794 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2012-02-24 22:53:42 +00:00
parent cc07e34bfc
commit 85738261a5
5 changed files with 38 additions and 9 deletions

View file

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

8
dir.c
View file

@ -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;
}

10
error.c
View file

@ -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);

View file

@ -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

View file

@ -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