ruby-changes:22764
From: naruse <ko1@a...>
Date: Sat, 25 Feb 2012 21:26:06 +0900 (JST)
Subject: [ruby-changes:22764] naruse:r34813 (ruby_1_9_3): merge revision(s) 34794,34795:
naruse 2012-02-25 21:25:55 +0900 (Sat, 25 Feb 2012) New Revision: 34813 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=34813 Log: 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] Modified files: branches/ruby_1_9_3/ChangeLog branches/ruby_1_9_3/dir.c branches/ruby_1_9_3/error.c branches/ruby_1_9_3/test/ruby/test_dir_m17n.rb branches/ruby_1_9_3/test/ruby/test_io_m17n.rb branches/ruby_1_9_3/version.h Index: ruby_1_9_3/ChangeLog =================================================================== --- ruby_1_9_3/ChangeLog (revision 34812) +++ ruby_1_9_3/ChangeLog (revision 34813) @@ -1,3 +1,15 @@ +Sat Feb 25 21:18:12 2012 Nobuyoshi Nakada <nobu@r...> + + * 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@r...> + + * 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@r...> * lib/fileutils.rb: use chomp(?/) instead of sub to optimize and avoid @@ -3,9 +15,4 @@ to regexping invalid string. -Sat Feb 25 17:09:53 2012 Nobuyoshi Nakada <nobu@r...> - - * 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@r...> Index: ruby_1_9_3/dir.c =================================================================== --- ruby_1_9_3/dir.c (revision 34812) +++ ruby_1_9_3/dir.c (revision 34813) @@ -387,7 +387,7 @@ { 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 @@ } 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 @@ 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; } Index: ruby_1_9_3/error.c =================================================================== --- ruby_1_9_3/error.c (revision 34812) +++ ruby_1_9_3/error.c (revision 34813) @@ -1128,15 +1128,13 @@ 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); Index: ruby_1_9_3/version.h =================================================================== --- ruby_1_9_3/version.h (revision 34812) +++ ruby_1_9_3/version.h (revision 34813) @@ -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 Index: ruby_1_9_3/test/ruby/test_io_m17n.rb =================================================================== --- ruby_1_9_3/test/ruby/test_io_m17n.rb (revision 34812) +++ ruby_1_9_3/test/ruby/test_io_m17n.rb (revision 34813) @@ -2326,6 +2326,17 @@ } 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")] Index: ruby_1_9_3/test/ruby/test_dir_m17n.rb =================================================================== --- ruby_1_9_3/test/ruby/test_dir_m17n.rb (revision 34812) +++ ruby_1_9_3/test/ruby/test_dir_m17n.rb (revision 34813) @@ -214,6 +214,17 @@ } 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")] -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/