diff options
| author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-07-25 14:35:21 +0000 |
|---|---|---|
| committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-07-25 14:35:21 +0000 |
| commit | fa46c2d929aa7ae85a5f79ffcaeee63ee58db793 (patch) | |
| tree | a9c4b1b6e3b1a860b3369c07f523976342cd7d08 | |
| parent | 6e45597cfe54f4e61d3d44d7867d3c28e1f3d1dd (diff) | |
* lib/webrick/httputils.rb (WEBrick::HTTPUtils#split_header_value):
reduce backtrack. based on a fix by Christian Neukirchen
<chneukirchen AT gmail.com>.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@18220 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
| -rw-r--r-- | ChangeLog | 6 | ||||
| -rw-r--r-- | lib/webrick/httputils.rb | 16 |
2 files changed, 10 insertions, 12 deletions
@@ -1,3 +1,9 @@ +Fri Jul 25 23:35:18 2008 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * 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@ruby-lang.org> * regex.c (xmalloc, xrealloc, xfree): not to use ruby managed memory. 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 |
