diff options
author | gotoyuzo <gotoyuzo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-01-18 06:03:43 +0000 |
---|---|---|
committer | gotoyuzo <gotoyuzo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-01-18 06:03:43 +0000 |
commit | fb18f0d9736ba1898523518e690c2995df413353 (patch) | |
tree | 9e236a812f7161e3f6953126ee67d46bbead3a75 /lib/webrick/httputils.rb | |
parent | 9f1945ac53f53bfbf4813f3ddda33cfb40e780c8 (diff) |
* lib/webrick/ssl.rb (WEBrick::Config::SSL): the default value
of :SSLEnable is false.
* lib/webrick/server.rb (WEBrick::Daemon.start): prepared stdio
don't allow changing its mode.
* lib/webrick/httpproxy.rb (WEBrick::HTTPProxyServer#proxy_service):
should delete trailing LF from the result of pack("m*").
* lib/webrick/httpproxy.rb (WEBrick::HTTPProxyServer#proxy_connect):
- should delete trailing LF from the result of pack("m*").
- clear Request-Line not to send the response by HTTPServer#run.
* lib/webrick/httputils (WEBrick::HTTPUtils.parse_qvalues):
refine regexp (and change the name of a local variable).
* lib/webrick/httputils.rb (WEBrick::HTTPUtils#escape_path): add
new method to escape URI path component.
* lib/webrick/cgi.rb (WEBrick::CGI::Socket#request_line): should
escape SCRIPT_NAME and PATH_INFO before being parsed as a URI.
* test/webrick/*, sample/webrick/httpproxy.rb: add new file.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@7784 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/webrick/httputils.rb')
-rw-r--r-- | lib/webrick/httputils.rb | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/lib/webrick/httputils.rb b/lib/webrick/httputils.rb index 18e3e25887..e0855222f1 100644 --- a/lib/webrick/httputils.rb +++ b/lib/webrick/httputils.rb @@ -179,14 +179,14 @@ module WEBrick if value parts = value.split(/,\s*/) parts.each {|part| - if m = %r{^([^\s,]+?)(?:;\s*q=([\d]+(?:\.[\d]+)))?$}.match(part) - lang = m[1] + if m = %r{^([^\s,]+?)(?:;\s*q=(\d+(?:\.\d+)?))?$}.match(part) + val = m[1] q = (m[2] or 1).to_f - tmp.push([lang, q]) + tmp.push([val, q]) end } - tmp = tmp.sort_by{|lang, q| -q} - tmp.collect!{|lang, q| lang} + tmp = tmp.sort_by{|val, q| -q} + tmp.collect!{|val, q| val} end return tmp end @@ -352,15 +352,18 @@ module WEBrick unwise = '{}|\\^[]`' nonascii = (0x80..0xff).collect{|c| c.chr }.join + module_function + def _make_regex(str) /([#{Regexp.escape(str)}])/n end + def _make_regex!(str) /([^#{Regexp.escape(str)}])/n end def _escape(str, regex) str.gsub(regex){ "%%%02X" % $1[0] } end def _unescape(str, regex) str.gsub(regex){ $1.hex.chr } end - module_function :_make_regex, :_escape, :_unescape UNESCAPED = _make_regex(control+space+delims+unwise+nonascii) UNESCAPED_FORM = _make_regex(reserved+control+delims+unwise+nonascii) NONASCII = _make_regex(nonascii) ESCAPED = /%([0-9a-fA-F]{2})/ + UNESCAPED_PCHAR = _make_regex!(unreserved+":@&=+$,") def escape(str) _escape(str, UNESCAPED) @@ -380,12 +383,14 @@ module WEBrick _unescape(str.gsub(/\+/, " "), ESCAPED) end + def escape_path(str) + str.split("/").collect{|i| + _escape(i, UNESCAPED_PCHAR) + }.join("/") + end + def escape8bit(str) _escape(str, NONASCII) end - - module_function :escape, :unescape, :escape_form, :unescape_form, - :escape8bit - end end |