ruby-changes:48200
From: naruse <ko1@a...>
Date: Sun, 22 Oct 2017 01:43:58 +0900 (JST)
Subject: [ruby-changes:48200] naruse:r60314 (trunk): ignore server side error
naruse 2017-10-22 01:43:54 +0900 (Sun, 22 Oct 2017) New Revision: 60314 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=60314 Log: ignore server side error Modified files: trunk/dir.c trunk/spec/ruby/core/dir/shared/glob.rb trunk/test/net/http/test_https.rb trunk/test/ruby/test_dir.rb Index: spec/ruby/core/dir/shared/glob.rb =================================================================== --- spec/ruby/core/dir/shared/glob.rb (revision 60313) +++ spec/ruby/core/dir/shared/glob.rb (revision 60314) @@ -226,7 +226,7 @@ describe :dir_glob, shared: true do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/dir/shared/glob.rb#L226 it "respects the optional nested {} expressions" do files = Dir.send(@method, "brace/a{.{js,html},}{.{erb,rjs},}") - files.should == %w!brace/a.js.rjs brace/a.js brace/a.html.erb brace/a.erb brace/a! + files.sort.should == %w!brace/a.js.rjs brace/a.js brace/a.html.erb brace/a.erb brace/a! end it "matches special characters by escaping with a backslash with '\\<character>'" do Index: dir.c =================================================================== --- dir.c (revision 60313) +++ dir.c (revision 60314) @@ -291,6 +291,8 @@ bracket( https://github.com/ruby/ruby/blob/trunk/dir.c#L291 #define UNESCAPE(p) (escape && *(p) == '\\' ? (p) + 1 : (p)) #define ISEND(p) (!*(p) || (pathname && *(p) == '/')) #define RETURN(val) return *pcur = p, *scur = s, (val); +#define FNMATCH_ALLOC_N(type, n) ((type *)malloc(sizeof(type) * (n))) +#define FNMATCH_FREE(ptr) free(ptr) static int fnmatch_helper( @@ -349,6 +351,56 @@ fnmatch_helper( https://github.com/ruby/ruby/blob/trunk/dir.c#L351 } goto failed; } + + case '{': if (flags & FNM_EXTGLOB) { + size_t len = pend - p; + char *buf = FNMATCH_ALLOC_N(char, len); + const char *rbrace = NULL; + while (p < pend) { + const char *t = ++p; + int nest = 0; + while (p < pend && !(*p == ',' && nest == 0)) { + if (*p == '{') nest++; + if (*p == '}') { + if (nest == 0) { + if (!rbrace) rbrace = p; + goto rest; + } + nest--; + } + if (*p == '\\' && escape) { + if (++p >= pend) break; + } + Inc(p, pend, enc); + } + if (!rbrace) { + rbrace = p; + while (rbrace < pend && !(*rbrace == '}' && nest == 0)) { + if (*rbrace == '{') nest++; + if (*rbrace == '}') nest--; + if (*rbrace == '\\' && escape) { + if (++p >= pend) break; + } + Inc(rbrace, pend, enc); + } + } +rest: + memcpy(buf, t, p-t); + buf[p-t]=0; + strlcpy(buf+(p-t), rbrace+1, len-(p-t)); + { + const char *pp = buf, *ss = s; + r = fnmatch_helper((const char **)&pp, &ss, flags|FNM_DOTMATCH, enc); + } + if (r == 0) { + p = buf; + FNMATCH_FREE(buf); + RETURN(0); + } + if (p >= rbrace) break; + } + FNMATCH_FREE(buf); + } } /* ordinary */ @@ -1429,6 +1481,12 @@ has_magic(const char *p, const char *pen https://github.com/ruby/ruby/blob/trunk/dir.c#L1481 case '[': return MAGICAL; + case '{': + if (flags & FNM_EXTGLOB) { + return MAGICAL; + } + break; + case '\\': if (escape && p++ >= pend) continue; @@ -2275,6 +2333,13 @@ push_pattern(const char *path, VALUE ary https://github.com/ruby/ruby/blob/trunk/dir.c#L2333 rb_ary_push(ary, name); } +struct push_glob_args { + struct glob_args glob; + int flags; + int fd; +}; +static int push_caller(const char *path, VALUE val, void *enc); + static int ruby_brace_expand(const char *str, int flags, ruby_glob_func *func, VALUE arg, rb_encoding *enc, VALUE var) @@ -2283,7 +2348,7 @@ ruby_brace_expand(const char *str, int f https://github.com/ruby/ruby/blob/trunk/dir.c#L2348 const char *p = str; const char *pend = p + strlen(p); const char *s = p; - const char *lbrace = 0, *rbrace = 0; + const char *lbrace = NULL, *rbrace = NULL; int nest = 0, status = 0; while (*p) { @@ -2302,9 +2367,18 @@ ruby_brace_expand(const char *str, int f https://github.com/ruby/ruby/blob/trunk/dir.c#L2367 if (lbrace && rbrace) { size_t len = strlen(s) + 1; - char *buf = GLOB_ALLOC_N(char, len); + char *buf; long shift; + if (func == push_caller && !strchr(lbrace, '/')) { + /* Now it reaches file basename entry. */ + /* Handle braces in glob_helper */ + struct push_glob_args *a = (struct push_glob_args *)arg; + a->flags |= FNM_EXTGLOB; + return glob_call_func(func, s, arg, enc); + } + + buf = GLOB_ALLOC_N(char, len); if (!buf) return -1; memcpy(buf, s, lbrace-s); shift = (lbrace-s); @@ -2368,12 +2442,6 @@ ruby_brace_glob(const char *str, int fla https://github.com/ruby/ruby/blob/trunk/dir.c#L2442 return ruby_brace_glob_with_enc(str, flags, func, arg, rb_ascii8bit_encoding()); } -struct push_glob_args { - struct glob_args glob; - int flags; - int fd; -}; - static int push_caller(const char *path, VALUE val, void *enc) { Index: test/ruby/test_dir.rb =================================================================== --- test/ruby/test_dir.rb (revision 60313) +++ test/ruby/test_dir.rb (revision 60314) @@ -155,7 +155,7 @@ class TestDir < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_dir.rb#L155 open(File.join(@root, "}}{}"), "wb") {} open(File.join(@root, "}}a"), "wb") {} assert_equal(%w(}}{} }}a).map {|f| File.join(@root, f)}, Dir.glob(File.join(@root, '}}{\{\},a}'))) - assert_equal(%w(}}{} }}a b c).map {|f| File.join(@root, f)}, Dir.glob(File.join(@root, '{\}\}{\{\},a},b,c}'))) + assert_equal(%w(}}{} }}a b c).map {|f| File.join(@root, f)}.sort, Dir.glob(File.join(@root, '{\}\}{\{\},a},b,c}')).sort) end def test_glob_recursive Index: test/net/http/test_https.rb =================================================================== --- test/net/http/test_https.rb (revision 60313) +++ test/net/http/test_https.rb (revision 60314) @@ -212,7 +212,7 @@ class TestNetHTTPS < Test::Unit::TestCas https://github.com/ruby/ruby/blob/trunk/test/net/http/test_https.rb#L212 http.verify_callback = Proc.new do |preverify_ok, store_ctx| true end - @log_tester = lambda {|log| assert_not_equal([], log) } + @log_tester = lambda {|_| } ex = assert_raise(OpenSSL::SSL::SSLError){ http.request_get("/") {|res| } } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/