* lib/cgi/core.rb: check if Tempfile is defined before use it.
* lib/cgi/core.rb: remove tempfiles only if tempfiles exist git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
0ba78cb2f7
commit
0ba4526d06
10
ChangeLog
10
ChangeLog
@ -1,9 +1,19 @@
|
|||||||
|
Mon Nov 5 10:57:59 2012 NARUSE, Yui <naruse@ruby-lang.org>
|
||||||
|
|
||||||
|
* lib/cgi/core.rb: check if Tempfile is defined before use it.
|
||||||
|
|
||||||
|
* lib/cgi/core.rb: remove tempfiles only if tempfiles exist
|
||||||
|
|
||||||
Mon Nov 5 12:17:00 2012 Zachary Scott <zachary@zacharyscott.net>
|
Mon Nov 5 12:17:00 2012 Zachary Scott <zachary@zacharyscott.net>
|
||||||
|
|
||||||
* lib/uri/http.rb (URI::HTTP.build): Fix example
|
* lib/uri/http.rb (URI::HTTP.build): Fix example
|
||||||
Patch by Carina C. Zona
|
Patch by Carina C. Zona
|
||||||
[Fixes #209 Github]
|
[Fixes #209 Github]
|
||||||
|
|
||||||
|
Mon Nov 5 09:55:05 2012 Takeyuki FUJIOKA <xibbar@ruby-lang.org>
|
||||||
|
|
||||||
|
* lib/cgi/core.rb: remove tempfile more early.
|
||||||
|
|
||||||
Sun Nov 4 20:29:46 2012 Takeyuki FUJIOKA <xibbar@ruby-lang.org>
|
Sun Nov 4 20:29:46 2012 Takeyuki FUJIOKA <xibbar@ruby-lang.org>
|
||||||
|
|
||||||
* lib/cgi.rb, lib/cgi/*/rb: rename CGI#header to CGI#http_header,
|
* lib/cgi.rb, lib/cgi/*/rb: rename CGI#header to CGI#http_header,
|
||||||
|
@ -484,7 +484,7 @@ class CGI
|
|||||||
(n += 1) < max_count or raise StandardError.new("too many parameters.")
|
(n += 1) < max_count or raise StandardError.new("too many parameters.")
|
||||||
## create body (StringIO or Tempfile)
|
## create body (StringIO or Tempfile)
|
||||||
body = create_body(bufsize < content_length)
|
body = create_body(bufsize < content_length)
|
||||||
tempfiles << body if body.kind_of? Tempfile
|
tempfiles << body if defined?(Tempfile) && body.kind_of?(Tempfile)
|
||||||
class << body
|
class << body
|
||||||
if method_defined?(:path)
|
if method_defined?(:path)
|
||||||
alias local_path path
|
alias local_path path
|
||||||
@ -542,7 +542,7 @@ class CGI
|
|||||||
name = $1 || $2 || ''
|
name = $1 || $2 || ''
|
||||||
if body.original_filename.empty?
|
if body.original_filename.empty?
|
||||||
value=body.read.dup.force_encoding(@accept_charset)
|
value=body.read.dup.force_encoding(@accept_charset)
|
||||||
body.unlink if body.kind_of? Tempfile
|
body.unlink if defined?(Tempfile) && body.kind_of?(Tempfile)
|
||||||
(params[name] ||= []) << value
|
(params[name] ||= []) << value
|
||||||
unless value.valid_encoding?
|
unless value.valid_encoding?
|
||||||
if @accept_charset_error_block
|
if @accept_charset_error_block
|
||||||
@ -567,7 +567,7 @@ class CGI
|
|||||||
params.default = []
|
params.default = []
|
||||||
params
|
params
|
||||||
ensure
|
ensure
|
||||||
if $!
|
if $! && tempfiles
|
||||||
tempfiles.each {|t|
|
tempfiles.each {|t|
|
||||||
if t.path
|
if t.path
|
||||||
t.unlink
|
t.unlink
|
||||||
|
@ -2,6 +2,7 @@ require 'test/unit'
|
|||||||
require 'cgi'
|
require 'cgi'
|
||||||
require 'tempfile'
|
require 'tempfile'
|
||||||
require 'stringio'
|
require 'stringio'
|
||||||
|
require_relative '../ruby/envutil'
|
||||||
|
|
||||||
|
|
||||||
##
|
##
|
||||||
@ -332,6 +333,34 @@ class CGIMultipartTest < Test::Unit::TestCase
|
|||||||
cgi['file'].unlink if cgi['file'].kind_of? Tempfile
|
cgi['file'].unlink if cgi['file'].kind_of? Tempfile
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_cgi_multipart_without_tempfile
|
||||||
|
assert_in_out_err([], <<-'EOM')
|
||||||
|
require 'cgi'
|
||||||
|
require 'stringio'
|
||||||
|
ENV['REQUEST_METHOD'] = 'POST'
|
||||||
|
ENV['CONTENT_TYPE'] = 'multipart/form-data; boundary=foobar1234'
|
||||||
|
body = <<-BODY
|
||||||
|
--foobar1234
|
||||||
|
Content-Disposition: form-data: name=\"name1\"
|
||||||
|
|
||||||
|
value1
|
||||||
|
--foobar1234
|
||||||
|
Content-Disposition: form-data: name=\"file1\"; filename=\"file1.html\"
|
||||||
|
Content-Type: text/html
|
||||||
|
|
||||||
|
<html>
|
||||||
|
<body><p>Hello</p></body>
|
||||||
|
</html>
|
||||||
|
|
||||||
|
--foobar1234--
|
||||||
|
BODY
|
||||||
|
body.gsub!(/\n/, "\r\n")
|
||||||
|
ENV['CONTENT_LENGTH'] = body.size.to_s
|
||||||
|
$stdin = StringIO.new(body)
|
||||||
|
CGI.new
|
||||||
|
EOM
|
||||||
|
end
|
||||||
|
|
||||||
###
|
###
|
||||||
|
|
||||||
self.instance_methods.each do |method|
|
self.instance_methods.each do |method|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user