ruby-changes:37451
From: nobu <ko1@a...>
Date: Sat, 7 Feb 2015 09:11:14 +0900 (JST)
Subject: [ruby-changes:37451] nobu:r49532 (trunk): dir.c: fix escaping multibyte char
nobu 2015-02-07 09:11:00 +0900 (Sat, 07 Feb 2015) New Revision: 49532 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=49532 Log: dir.c: fix escaping multibyte char * dir.c (has_magic): fix escaping multibyte char, with glob meta-char in trailing bytes, e.g., Shift-JIS Modified files: trunk/dir.c trunk/test/ruby/test_dir_m17n.rb Index: dir.c =================================================================== --- dir.c (revision 49531) +++ dir.c (revision 49532) @@ -1205,9 +1205,9 @@ has_magic(const char *p, const char *pen https://github.com/ruby/ruby/blob/trunk/dir.c#L1205 return MAGICAL; case '\\': - if (escape && !(c = *p++)) - return PLAIN; - continue; + if (escape && p++ >= pend) + continue; + break; #ifdef _WIN32 case '~': Index: test/ruby/test_dir_m17n.rb =================================================================== --- test/ruby/test_dir_m17n.rb (revision 49531) +++ test/ruby/test_dir_m17n.rb (revision 49532) @@ -352,6 +352,16 @@ class TestDir_M17N < Test::Unit::TestCas https://github.com/ruby/ruby/blob/trunk/test/ruby/test_dir_m17n.rb#L352 end end + def test_glob_escape_multibyte + name = "\x81\\".force_encoding(Encoding::Shift_JIS) + with_tmpdir do + open(name, "w") {} rescue next + match, = Dir.glob("#{name}*") + next unless match and match.encoding == Encoding::Shift_JIS + assert_equal([name], Dir.glob("\\#{name}*")) + end + end + def test_entries_compose bug7267 = '[ruby-core:48745] [Bug #7267]' -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/