ruby-changes:41803
From: nobu <ko1@a...>
Date: Sat, 20 Feb 2016 13:04:35 +0900 (JST)
Subject: [ruby-changes:41803] nobu:r53877 (trunk): dir.c: paths as UTF-8
nobu 2016-02-20 13:04:59 +0900 (Sat, 20 Feb 2016) New Revision: 53877 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=53877 Log: dir.c: paths as UTF-8 * dir.c (push_pattern, push_glob): deal with read paths as UTF-8 to stat later, on Windows as well as OS X. [ruby-core:73868] [Bug #12081] Modified files: trunk/ChangeLog trunk/dir.c trunk/test/ruby/test_dir_m17n.rb Index: test/ruby/test_dir_m17n.rb =================================================================== --- test/ruby/test_dir_m17n.rb (revision 53876) +++ test/ruby/test_dir_m17n.rb (revision 53877) @@ -365,10 +365,17 @@ class TestDir_M17N < Test::Unit::TestCas https://github.com/ruby/ruby/blob/trunk/test/ruby/test_dir_m17n.rb#L365 def test_glob_encoding with_tmpdir do - %W"file_one.ext file_two.ext".each {|f| open(f, "w") {}} + list = %W"file_one.ext file_two.ext \u{6587 4ef6}1.txt \u{6587 4ef6}2.txt" + list.each {|f| open(f, "w") {}} a = "file_one*".force_encoding Encoding::IBM437 b = "file_two*".force_encoding Encoding::EUC_JP assert_equal([a, b].map(&:encoding), Dir[a, b].map(&:encoding)) + dir = "\u{76EE 5F551}" + Dir.mkdir(dir) + list << dir + bug12081 = '[ruby-core:73868] [Bug #12081]' + a = "*".force_encoding("us-ascii") + assert_equal(list, Dir[a].map {|n| n.encode(Encoding::UTF_8)}.sort, bug12081) end end Index: dir.c =================================================================== --- dir.c (revision 53876) +++ dir.c (revision 53877) @@ -2050,7 +2050,7 @@ rb_glob(const char *path, void (*func)(c https://github.com/ruby/ruby/blob/trunk/dir.c#L2050 static void push_pattern(const char *path, VALUE ary, void *enc) { -#ifdef __APPLE__ +#if defined _WIN32 || defined __APPLE__ VALUE name = rb_utf8_str_new_cstr(path); rb_encoding *eenc = rb_default_internal_encoding(); OBJ_TAINT(name); @@ -2171,7 +2171,7 @@ push_glob(VALUE ary, VALUE str, int flag https://github.com/ruby/ruby/blob/trunk/dir.c#L2171 struct push_glob_args args; rb_encoding *enc = rb_enc_get(str); -#ifdef __APPLE__ +#if defined _WIN32 || defined __APPLE__ str = rb_str_encode_ospath(str); #endif if (rb_enc_to_index(enc) == ENCINDEX_US_ASCII) @@ -2183,7 +2183,7 @@ push_glob(VALUE ary, VALUE str, int flag https://github.com/ruby/ruby/blob/trunk/dir.c#L2183 args.glob.value = ary; args.glob.enc = enc; args.flags = flags; -#ifdef __APPLE__ +#if defined _WIN32 || defined __APPLE__ enc = rb_utf8_encoding(); #endif Index: ChangeLog =================================================================== --- ChangeLog (revision 53876) +++ ChangeLog (revision 53877) @@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Sat Feb 20 13:04:22 2016 Nobuyoshi Nakada <nobu@r...> + + * dir.c (push_pattern, push_glob): deal with read paths as UTF-8 + to stat later, on Windows as well as OS X. + [ruby-core:73868] [Bug #12081] + Sat Feb 20 01:53:33 2016 Nobuyoshi Nakada <nobu@r...> * object.c (rb_mod_const_get): make error message at uninterned -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/