ruby-changes:27610
From: nagachika <ko1@a...>
Date: Sat, 9 Mar 2013 22:35:52 +0900 (JST)
Subject: [ruby-changes:27610] nagachika:r39662 (ruby_2_0_0): merge revision(s) 39413: [Backport #7911]
nagachika 2013-03-09 22:35:41 +0900 (Sat, 09 Mar 2013) New Revision: 39662 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=39662 Log: 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] Modified directories: branches/ruby_2_0_0/ Modified files: branches/ruby_2_0_0/ChangeLog branches/ruby_2_0_0/dir.c branches/ruby_2_0_0/test/ruby/test_fnmatch.rb branches/ruby_2_0_0/version.h Index: ruby_2_0_0/ChangeLog =================================================================== --- ruby_2_0_0/ChangeLog (revision 39661) +++ ruby_2_0_0/ChangeLog (revision 39662) @@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/ChangeLog#L1 +Sat Mar 9 22:35:22 2013 Nobuyoshi Nakada <nobu@r...> + + * 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@r...> * test/test_rbconfig.rb (TestRbConfig): fix r39372. Index: ruby_2_0_0/dir.c =================================================================== --- ruby_2_0_0/dir.c (revision 39661) +++ ruby_2_0_0/dir.c (revision 39662) @@ -1919,7 +1919,24 @@ fnmatch_brace(const char *pattern, VALUE https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/dir.c#L1919 { 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, VA https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/dir.c#L2046 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); Index: ruby_2_0_0/version.h =================================================================== --- ruby_2_0_0/version.h (revision 39661) +++ ruby_2_0_0/version.h (revision 39662) @@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/version.h#L1 #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 Index: ruby_2_0_0/test/ruby/test_fnmatch.rb =================================================================== --- ruby_2_0_0/test/ruby/test_fnmatch.rb (revision 39661) +++ ruby_2_0_0/test/ruby/test_fnmatch.rb (revision 39662) @@ -109,4 +109,19 @@ class TestFnmatch < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/test/ruby/test_fnmatch.rb#L109 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 Property changes on: ruby_2_0_0 ___________________________________________________________________ Modified: svn:mergeinfo Merged /trunk:r39413 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/