summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-02-24 22:53:42 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-02-24 22:53:42 +0000
commit85738261a582ceef498b86b784171fba59bf60cc (patch)
treeaa97e06f7c4474313689463864dcb672a3d93552
parentcc07e34bfcc9675924fd0546b46eb53c3d972ab8 (diff)
* 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
-rw-r--r--ChangeLog7
-rw-r--r--dir.c8
-rw-r--r--error.c10
-rw-r--r--test/ruby/test_dir_m17n.rb11
-rw-r--r--test/ruby/test_io_m17n.rb11
5 files changed, 38 insertions, 9 deletions
diff --git a/ChangeLog b/ChangeLog
index a11c2bc878..e0b9afcf04 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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.
diff --git a/dir.c b/dir.c
index 40d304cdf4..8383adc6f0 100644
--- a/dir.c
+++ b/dir.c
@@ -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;
}
diff --git a/error.c b/error.c
index 77ca3a91f3..c212c53b3f 100644
--- a/error.c
+++ b/error.c
@@ -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