ruby-changes:6704
From: nobu <ko1@a...>
Date: Fri, 25 Jul 2008 23:35:39 +0900 (JST)
Subject: [ruby-changes:6704] Ruby:r18220 (ruby_1_8, trunk): * lib/webrick/httputils.rb (WEBrick::HTTPUtils#split_header_value):
nobu 2008-07-25 23:35:21 +0900 (Fri, 25 Jul 2008) New Revision: 18220 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=18220 Log: * lib/webrick/httputils.rb (WEBrick::HTTPUtils#split_header_value): reduce backtrack. based on a fix by Christian Neukirchen <chneukirchen AT gmail.com>. Modified files: branches/ruby_1_8/ChangeLog branches/ruby_1_8/lib/webrick/httputils.rb trunk/ChangeLog trunk/lib/webrick/httputils.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 18219) +++ ChangeLog (revision 18220) @@ -1,3 +1,9 @@ +Fri Jul 25 23:35:18 2008 Nobuyoshi Nakada <nobu@r...> + + * lib/webrick/httputils.rb (WEBrick::HTTPUtils#split_header_value): + reduce backtrack. based on a fix by Christian Neukirchen + <chneukirchen AT gmail.com>. + Fri Jul 25 21:55:38 2008 Yusuke Endoh <mame@t...> * test/ruby/enc/test_koi8.rb: move from test/ruby/test_koi8.rb. Index: lib/webrick/httputils.rb =================================================================== --- lib/webrick/httputils.rb (revision 18219) +++ lib/webrick/httputils.rb (revision 18220) @@ -23,16 +23,8 @@ ret = path.dup ret.gsub!(%r{/+}o, '/') # // => / - while ret.sub!(%r{/\.(/|\Z)}o, '/'); end # /. => / - begin # /foo/.. => /foo - match = ret.sub!(%r{/([^/]+)/\.\.(/|\Z)}o){ - if $1 == ".." - raise "abnormal path `#{path}'" - else - "/" - end - } - end while match + while ret.sub!(%r'/\.(?:/|\Z)', '/'); end # /. => / + while ret.sub!(%r'/(?!\.\./)[^/]+/\.\.(?:/|\Z)', '/'); end # /foo/.. => /foo raise "abnormal path `#{path}'" if %r{/\.\.(/|\Z)} =~ ret ret @@ -155,8 +147,8 @@ module_function :parse_header def split_header_value(str) - str.scan(/((?:"(?:\\.|[^"])+?"|[^",]+)+) - (?:,\s*|\Z)/xn).collect{|v| v[0] } + str.scan(%r'\G((?:"(?:\\.|[^"])+?"|[^",]+)+) + (?:,\s*|\Z)'xn).flatten end module_function :split_header_value Index: ruby_1_8/ChangeLog =================================================================== --- ruby_1_8/ChangeLog (revision 18219) +++ ruby_1_8/ChangeLog (revision 18220) @@ -1,3 +1,9 @@ +Fri Jul 25 23:35:18 2008 Nobuyoshi Nakada <nobu@r...> + + * lib/webrick/httputils.rb (WEBrick::HTTPUtils#split_header_value): + reduce backtrack. based on a fix by Christian Neukirchen + <chneukirchen AT gmail.com>. + Fri Jul 25 19:45:42 2008 Nobuyoshi Nakada <nobu@r...> * regex.c (xmalloc, xrealloc, xfree): not to use ruby managed memory. Index: ruby_1_8/lib/webrick/httputils.rb =================================================================== --- ruby_1_8/lib/webrick/httputils.rb (revision 18219) +++ ruby_1_8/lib/webrick/httputils.rb (revision 18220) @@ -23,16 +23,8 @@ ret = path.dup ret.gsub!(%r{/+}o, '/') # // => / - while ret.sub!(%r{/\.(/|\Z)}o, '/'); end # /. => / - begin # /foo/.. => /foo - match = ret.sub!(%r{/([^/]+)/\.\.(/|\Z)}o){ - if $1 == ".." - raise "abnormal path `#{path}'" - else - "/" - end - } - end while match + while ret.sub!(%r'/\.(?:/|\Z)', '/'); end # /. => / + while ret.sub!(%r'/(?!\.\./)[^/]+/\.\.(?:/|\Z)', '/'); end # /foo/.. => /foo raise "abnormal path `#{path}'" if %r{/\.\.(/|\Z)} =~ ret ret @@ -154,8 +146,8 @@ module_function :parse_header def split_header_value(str) - str.scan(/((?:"(?:\\.|[^"])+?"|[^",]+)+) - (?:,\s*|\Z)/xn).collect{|v| v[0] } + str.scan(%r'\G((?:"(?:\\.|[^"])+?"|[^",]+)+) + (?:,\s*|\Z)'xn).flatten end module_function :split_header_value -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/