mirror of
https://github.com/ruby/ruby.git
synced 2025-09-16 00:54:01 +02:00
merge revision(s) 39413: [Backport #7911]
* dir.c (file_s_fnmatch, fnmatch_brace): encoding-incompatible pattern and string do not match, instead of exception. [ruby-dev:47069] [Bug #7911] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_0_0@39662 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
5a5df65d9d
commit
cda3c63c7d
4 changed files with 42 additions and 3 deletions
|
@ -1,3 +1,9 @@
|
|||
Sat Mar 9 22:35:22 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* dir.c (file_s_fnmatch, fnmatch_brace): encoding-incompatible pattern
|
||||
and string do not match, instead of exception. [ruby-dev:47069]
|
||||
[Bug #7911]
|
||||
|
||||
Sat Mar 9 22:18:43 2013 NARUSE, Yui <naruse@ruby-lang.org>
|
||||
|
||||
* test/test_rbconfig.rb (TestRbConfig): fix r39372.
|
||||
|
|
22
dir.c
22
dir.c
|
@ -1919,7 +1919,24 @@ fnmatch_brace(const char *pattern, VALUE val, void *enc)
|
|||
{
|
||||
struct brace_args *arg = (struct brace_args *)val;
|
||||
VALUE path = arg->value;
|
||||
rb_encoding *enc_pattern = enc;
|
||||
rb_encoding *enc_path = rb_enc_get(path);
|
||||
|
||||
if (enc_pattern != enc_path) {
|
||||
if (!rb_enc_asciicompat(enc_pattern))
|
||||
return FNM_NOMATCH;
|
||||
if (!rb_enc_asciicompat(enc_path))
|
||||
return FNM_NOMATCH;
|
||||
if (!rb_enc_str_asciionly_p(path)) {
|
||||
int cr = ENC_CODERANGE_7BIT;
|
||||
long len = strlen(pattern);
|
||||
if (rb_str_coderange_scan_restartable(pattern, pattern + len,
|
||||
enc_pattern, &cr) != len)
|
||||
return FNM_NOMATCH;
|
||||
if (cr != ENC_CODERANGE_7BIT)
|
||||
return FNM_NOMATCH;
|
||||
}
|
||||
}
|
||||
return (fnmatch(pattern, enc, RSTRING_PTR(path), arg->flags) == 0);
|
||||
}
|
||||
|
||||
|
@ -2029,8 +2046,9 @@ file_s_fnmatch(int argc, VALUE *argv, VALUE obj)
|
|||
return Qtrue;
|
||||
}
|
||||
else {
|
||||
if (fnmatch(RSTRING_PTR(pattern), rb_enc_get(pattern), RSTRING_PTR(path),
|
||||
flags) == 0)
|
||||
rb_encoding *enc = rb_enc_compatible(pattern, path);
|
||||
if (!enc) return Qfalse;
|
||||
if (fnmatch(RSTRING_PTR(pattern), enc, RSTRING_PTR(path), flags) == 0)
|
||||
return Qtrue;
|
||||
}
|
||||
RB_GC_GUARD(pattern);
|
||||
|
|
|
@ -109,4 +109,19 @@ class TestFnmatch < Test::Unit::TestCase
|
|||
assert_file.for(feature5422).not_fnmatch?( "{.g,t}*", ".gem")
|
||||
assert_file.for(feature5422).fnmatch?("{.g,t}*", ".gem", File::FNM_EXTGLOB)
|
||||
end
|
||||
|
||||
def test_unmatched_encoding
|
||||
bug7911 = '[ruby-dev:47069] [Bug #7911]'
|
||||
path = "\u{3042}"
|
||||
pattern_ascii = 'a'.encode('US-ASCII')
|
||||
pattern_eucjp = path.encode('EUC-JP')
|
||||
assert_nothing_raised(ArgumentError, bug7911) do
|
||||
assert(!File.fnmatch(pattern_ascii, path))
|
||||
assert(!File.fnmatch(pattern_eucjp, path))
|
||||
assert(!File.fnmatch(pattern_ascii, path, File::FNM_CASEFOLD))
|
||||
assert(!File.fnmatch(pattern_eucjp, path, File::FNM_CASEFOLD))
|
||||
assert(File.fnmatch("{*,#{pattern_ascii}}", path, File::FNM_EXTGLOB))
|
||||
assert(File.fnmatch("{*,#{pattern_eucjp}}", path, File::FNM_EXTGLOB))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#define RUBY_VERSION "2.0.0"
|
||||
#define RUBY_RELEASE_DATE "2013-03-09"
|
||||
#define RUBY_PATCHLEVEL 31
|
||||
#define RUBY_PATCHLEVEL 32
|
||||
|
||||
#define RUBY_RELEASE_YEAR 2013
|
||||
#define RUBY_RELEASE_MONTH 3
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue