summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-02-25 12:25:55 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-02-25 12:25:55 +0000
commit5e808b6ba38dbd974b617e80e2cf054eaaca604f (patch)
tree14d1fb78d676ba0073bc701136cda1d884a40292
parent1b21d03d76640db4c7c96709b78d973950385b1a (diff)
merge revision(s) 34794,34795:
* 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] * dir.c (dir_inspect), io.c (rb_io_inspect): keep encoding of path. [Bug #6072] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_3@34813 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog17
-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
-rw-r--r--version.h2
6 files changed, 44 insertions, 15 deletions
diff --git a/ChangeLog b/ChangeLog
index 0764ef42af..66f2a388d5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,13 +1,20 @@
+Sat Feb 25 21:18:12 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * dir.c (dir_inspect), io.c (rb_io_inspect): keep encoding of path.
+ [Bug #6072]
+
+Sat Feb 25 21:18:12 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 17:10:51 2012 NARUSE, Yui <naruse@ruby-lang.org>
* lib/fileutils.rb: use chomp(?/) instead of sub to optimize and avoid
to regexping invalid string.
-Sat Feb 25 17:09:53 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
-
- * dir.c (dir_inspect), io.c (rb_io_inspect): keep encoding of path.
- [Bug #6072]
-
Sat Feb 25 16:39:13 2012 NARUSE, Yui <naruse@ruby-lang.org>
* complex.c (nucomp_marshal_load): raise error on invalid data.
diff --git a/dir.c b/dir.c
index 695ccc743e..0987e8ecc4 100644
--- a/dir.c
+++ b/dir.c
@@ -387,7 +387,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) {
@@ -405,7 +405,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);
@@ -419,10 +421,10 @@ dir_initialize(int argc, VALUE *argv, VALUE dir)
dp->dir = opendir(RSTRING_PTR(dirname));
}
if (dp->dir == NULL) {
- rb_sys_fail(RSTRING_PTR(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 e5ca4e7c90..db9a46f72f 100644
--- a/error.c
+++ b/error.c
@@ -1128,15 +1128,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 33ba9e1557..b376393abf 100644
--- a/test/ruby/test_dir_m17n.rb
+++ b/test/ruby/test_dir_m17n.rb
@@ -214,6 +214,17 @@ class TestDir_M17N < Test::Unit::TestCase
}
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
+
def test_inspect_nonascii
bug6072 = '[ruby-dev:45280]'
paths = ["\u{3042}".encode("sjis"), "\u{ff}".encode("iso-8859-1")]
diff --git a/test/ruby/test_io_m17n.rb b/test/ruby/test_io_m17n.rb
index 13d792b633..2f71356f8e 100644
--- a/test/ruby/test_io_m17n.rb
+++ b/test/ruby/test_io_m17n.rb
@@ -2326,6 +2326,17 @@ EOT
}
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
+
def test_inspect_nonascii
bug6072 = '[ruby-dev:45280]'
paths = ["\u{3042}".encode("sjis"), "\u{ff}".encode("iso-8859-1")]
diff --git a/version.h b/version.h
index 6a21e5ecdc..8d7480c892 100644
--- a/version.h
+++ b/version.h
@@ -1,5 +1,5 @@
#define RUBY_VERSION "1.9.3"
-#define RUBY_PATCHLEVEL 146
+#define RUBY_PATCHLEVEL 147
#define RUBY_RELEASE_DATE "2012-02-25"
#define RUBY_RELEASE_YEAR 2012