1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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
This commit is contained in:
nobu 2015-02-07 00:11:00 +00:00
parent 6548425ee0
commit 461c38a973
2 changed files with 13 additions and 3 deletions

6
dir.c
View file

@ -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 '~':

View file

@ -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]'