mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* lib/cgi.rb: reduce eval.
* lib/cgi.rb (CGI::QueryExtension::read_multipart): alias path to local_path. [ruby-list:38883] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5249 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
d7ff8a6469
commit
3fdd33b70c
2 changed files with 49 additions and 68 deletions
|
@ -1,3 +1,10 @@
|
||||||
|
Mon Dec 22 20:38:44 2003 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* lib/cgi.rb: reduce eval.
|
||||||
|
|
||||||
|
* lib/cgi.rb (CGI::QueryExtension::read_multipart): alias path to
|
||||||
|
local_path. [ruby-list:38883]
|
||||||
|
|
||||||
Mon Dec 22 20:09:31 2003 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
|
Mon Dec 22 20:09:31 2003 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
|
||||||
|
|
||||||
* test/soap/test_property.rb: remove duplicated test method.
|
* test/soap/test_property.rb: remove duplicated test method.
|
||||||
|
|
110
lib/cgi.rb
110
lib/cgi.rb
|
@ -921,27 +921,23 @@ class CGI
|
||||||
#
|
#
|
||||||
module QueryExtension
|
module QueryExtension
|
||||||
|
|
||||||
for env in %w[ CONTENT_LENGTH SERVER_PORT ]
|
%w[ CONTENT_LENGTH SERVER_PORT ].each do |env|
|
||||||
eval( <<-END )
|
define_method(env.sub(/^HTTP_/n, '').downcase) do
|
||||||
def #{env.sub(/^HTTP_/n, '').downcase}
|
val = env_table[env] && Integer(val)
|
||||||
env_table["#{env}"] && Integer(env_table["#{env}"])
|
end
|
||||||
end
|
|
||||||
END
|
|
||||||
end
|
end
|
||||||
|
|
||||||
for env in %w[ AUTH_TYPE CONTENT_TYPE GATEWAY_INTERFACE PATH_INFO
|
%w[ AUTH_TYPE CONTENT_TYPE GATEWAY_INTERFACE PATH_INFO
|
||||||
PATH_TRANSLATED QUERY_STRING REMOTE_ADDR REMOTE_HOST
|
PATH_TRANSLATED QUERY_STRING REMOTE_ADDR REMOTE_HOST
|
||||||
REMOTE_IDENT REMOTE_USER REQUEST_METHOD SCRIPT_NAME
|
REMOTE_IDENT REMOTE_USER REQUEST_METHOD SCRIPT_NAME
|
||||||
SERVER_NAME SERVER_PROTOCOL SERVER_SOFTWARE
|
SERVER_NAME SERVER_PROTOCOL SERVER_SOFTWARE
|
||||||
|
|
||||||
HTTP_ACCEPT HTTP_ACCEPT_CHARSET HTTP_ACCEPT_ENCODING
|
HTTP_ACCEPT HTTP_ACCEPT_CHARSET HTTP_ACCEPT_ENCODING
|
||||||
HTTP_ACCEPT_LANGUAGE HTTP_CACHE_CONTROL HTTP_FROM HTTP_HOST
|
HTTP_ACCEPT_LANGUAGE HTTP_CACHE_CONTROL HTTP_FROM HTTP_HOST
|
||||||
HTTP_NEGOTIATE HTTP_PRAGMA HTTP_REFERER HTTP_USER_AGENT ]
|
HTTP_NEGOTIATE HTTP_PRAGMA HTTP_REFERER HTTP_USER_AGENT ].each do |env|
|
||||||
eval( <<-END )
|
define_method(env.sub(/^HTTP_/n, '').downcase) do
|
||||||
def #{env.sub(/^HTTP_/n, '').downcase}
|
env_table[env]
|
||||||
env_table["#{env}"]
|
end
|
||||||
end
|
|
||||||
END
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Get the raw cookies as a string.
|
# Get the raw cookies as a string.
|
||||||
|
@ -1034,34 +1030,22 @@ class CGI
|
||||||
|
|
||||||
body.rewind
|
body.rewind
|
||||||
|
|
||||||
eval <<-END
|
|
||||||
def body.local_path
|
|
||||||
#{(body.class == StringIO)? "" : body.path.dump}
|
|
||||||
end
|
|
||||||
END
|
|
||||||
|
|
||||||
/Content-Disposition:.* filename="?([^\";]*)"?/ni.match(head)
|
/Content-Disposition:.* filename="?([^\";]*)"?/ni.match(head)
|
||||||
eval <<-END
|
filename = ($1 or "")
|
||||||
def body.original_filename
|
if /Mac/ni.match(env_table['HTTP_USER_AGENT']) and
|
||||||
#{
|
/Mozilla/ni.match(env_table['HTTP_USER_AGENT']) and
|
||||||
filename = ($1 or "").dup
|
(not /MSIE/ni.match(env_table['HTTP_USER_AGENT']))
|
||||||
if /Mac/ni.match(env_table['HTTP_USER_AGENT']) and
|
filename = CGI::unescape(filename)
|
||||||
/Mozilla/ni.match(env_table['HTTP_USER_AGENT']) and
|
end
|
||||||
(not /MSIE/ni.match(env_table['HTTP_USER_AGENT']))
|
|
||||||
CGI::unescape(filename)
|
|
||||||
else
|
|
||||||
filename
|
|
||||||
end.dump.untaint
|
|
||||||
}.taint
|
|
||||||
end
|
|
||||||
END
|
|
||||||
|
|
||||||
/Content-Type: (.*)/ni.match(head)
|
/Content-Type: (.*)/ni.match(head)
|
||||||
eval <<-END
|
content_type = ($1 or "")
|
||||||
def body.content_type
|
|
||||||
#{($1 or "").dump.untaint}.taint
|
(class << body; self; end).class_eval do
|
||||||
end
|
alias local_path path
|
||||||
END
|
define_method(:original_filename) {filename.dup.taint}
|
||||||
|
define_method(:content_type) {content_type.dup.taint}
|
||||||
|
end
|
||||||
|
|
||||||
/Content-Disposition:.* name="?([^\";]*)"?/ni.match(head)
|
/Content-Disposition:.* name="?([^\";]*)"?/ni.match(head)
|
||||||
name = $1.dup
|
name = $1.dup
|
||||||
|
@ -1239,31 +1223,22 @@ class CGI
|
||||||
#
|
#
|
||||||
# - -
|
# - -
|
||||||
def nn_element_def(element)
|
def nn_element_def(element)
|
||||||
<<-END.gsub(/element\.downcase/n, element.downcase).gsub(/element\.upcase/n, element.upcase)
|
nOE_element_def(element, <<-END)
|
||||||
"<element.upcase" + attributes.collect{|name, value|
|
|
||||||
next unless value
|
|
||||||
" " + CGI::escapeHTML(name) +
|
|
||||||
if true == value
|
|
||||||
""
|
|
||||||
else
|
|
||||||
'="' + CGI::escapeHTML(value) + '"'
|
|
||||||
end
|
|
||||||
}.to_s + ">" +
|
|
||||||
if block_given?
|
if block_given?
|
||||||
yield.to_s
|
yield.to_s
|
||||||
else
|
else
|
||||||
""
|
""
|
||||||
end +
|
end +
|
||||||
"</element.upcase>"
|
"</#{element.upcase}>"
|
||||||
END
|
END
|
||||||
end
|
end
|
||||||
|
|
||||||
# Generate code for an empty element.
|
# Generate code for an empty element.
|
||||||
#
|
#
|
||||||
# - O EMPTY
|
# - O EMPTY
|
||||||
def nOE_element_def(element)
|
def nOE_element_def(element, append = nil)
|
||||||
<<-END.gsub(/element\.downcase/n, element.downcase).gsub(/element\.upcase/n, element.upcase)
|
s = <<-END
|
||||||
"<element.upcase" + attributes.collect{|name, value|
|
"<#{element.upcase}" + attributes.collect{|name, value|
|
||||||
next unless value
|
next unless value
|
||||||
" " + CGI::escapeHTML(name) +
|
" " + CGI::escapeHTML(name) +
|
||||||
if true == value
|
if true == value
|
||||||
|
@ -1273,6 +1248,8 @@ class CGI
|
||||||
end
|
end
|
||||||
}.to_s + ">"
|
}.to_s + ">"
|
||||||
END
|
END
|
||||||
|
s.sub!(/\Z/, " +") << append if append
|
||||||
|
s
|
||||||
end
|
end
|
||||||
|
|
||||||
# Generate code for an element for which the end (and possibly the
|
# Generate code for an element for which the end (and possibly the
|
||||||
|
@ -1280,18 +1257,9 @@ class CGI
|
||||||
#
|
#
|
||||||
# O O or - O
|
# O O or - O
|
||||||
def nO_element_def(element)
|
def nO_element_def(element)
|
||||||
<<-END.gsub(/element\.downcase/n, element.downcase).gsub(/element\.upcase/n, element.upcase)
|
nOE_element_def(element, <<-END)
|
||||||
"<element.upcase" + attributes.collect{|name, value|
|
|
||||||
next unless value
|
|
||||||
" " + CGI::escapeHTML(name) +
|
|
||||||
if true == value
|
|
||||||
""
|
|
||||||
else
|
|
||||||
'="' + CGI::escapeHTML(value) + '"'
|
|
||||||
end
|
|
||||||
}.to_s + ">" +
|
|
||||||
if block_given?
|
if block_given?
|
||||||
yield.to_s + "</element.upcase>"
|
yield.to_s + "</#{element.upcase}>"
|
||||||
else
|
else
|
||||||
""
|
""
|
||||||
end
|
end
|
||||||
|
@ -2301,15 +2269,21 @@ class CGI
|
||||||
@cookies = CGI_COOKIES.nil? ? nil : CGI_COOKIES.dup
|
@cookies = CGI_COOKIES.nil? ? nil : CGI_COOKIES.dup
|
||||||
else
|
else
|
||||||
initialize_query() # set @params, @cookies
|
initialize_query() # set @params, @cookies
|
||||||
eval "CGI_PARAMS = @params.nil? ? nil : @params.dup"
|
params = @params.nil? ? nil : @params.dup
|
||||||
eval "CGI_COOKIES = @cookies.nil? ? nil : @cookies.dup"
|
cookies = @cookies.nil? ? nil : @cookies.dup
|
||||||
|
(class << self; self; end).class_eval do
|
||||||
|
const_set(:CGI_PARAMS, params)
|
||||||
|
const_set(:CGI_COOKIES, cookies)
|
||||||
|
end
|
||||||
if defined?(MOD_RUBY) and (RUBY_VERSION < "1.4.3")
|
if defined?(MOD_RUBY) and (RUBY_VERSION < "1.4.3")
|
||||||
raise "Please, use ruby1.4.3 or later."
|
raise "Please, use ruby1.4.3 or later."
|
||||||
else
|
else
|
||||||
at_exit() do
|
at_exit() do
|
||||||
if defined?(CGI_PARAMS)
|
if defined?(CGI_PARAMS)
|
||||||
CGI.class_eval("remove_const(:CGI_PARAMS)")
|
CGI.class_eval do
|
||||||
CGI.class_eval("remove_const(:CGI_COOKIES)")
|
remove_const(:CGI_PARAMS)
|
||||||
|
remove_const(:CGI_COOKIES)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue