From 8baf1746a4b399e784ad0a2b54bf522762a7189e Mon Sep 17 00:00:00 2001 From: shyouhei Date: Mon, 4 Aug 2008 05:21:05 +0000 Subject: merge revision(s) 18220: * lib/webrick/httputils.rb (WEBrick::HTTPUtils#split_header_value): reduce backtrack. based on a fix by Christian Neukirchen . git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8_7@18349 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/webrick/httputils.rb | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) (limited to 'lib') diff --git a/lib/webrick/httputils.rb b/lib/webrick/httputils.rb index c57af2c860..976d3e915e 100644 --- a/lib/webrick/httputils.rb +++ b/lib/webrick/httputils.rb @@ -23,16 +23,8 @@ module WEBrick 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 WEBrick 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 -- cgit v1.2.3