From 461c38a9737edda4baf909ef3993b588150c97b2 Mon Sep 17 00:00:00 2001 From: nobu Date: Sat, 7 Feb 2015 00:11:00 +0000 Subject: 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 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49532 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- dir.c | 6 +++--- test/ruby/test_dir_m17n.rb | 10 ++++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/dir.c b/dir.c index e2a19f142d..041d88af08 100644 --- a/dir.c +++ b/dir.c @@ -1205,9 +1205,9 @@ has_magic(const char *p, const char *pend, int flags, rb_encoding *enc) return MAGICAL; case '\\': - if (escape && !(c = *p++)) - return PLAIN; - continue; + if (escape && p++ >= pend) + continue; + break; #ifdef _WIN32 case '~': diff --git a/test/ruby/test_dir_m17n.rb b/test/ruby/test_dir_m17n.rb index a72598b360..04186e54a7 100644 --- a/test/ruby/test_dir_m17n.rb +++ b/test/ruby/test_dir_m17n.rb @@ -352,6 +352,16 @@ class TestDir_M17N < Test::Unit::TestCase 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]' -- cgit v1.2.3