mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
Update multipart tests to expose (another) bug in Rack's multipart parser
This commit is contained in:
@@ -33,6 +33,7 @@ end
|
||||
|
||||
gem 'rack', '>= 0.9.0'
|
||||
require 'rack'
|
||||
require 'action_controller/rack_ext'
|
||||
|
||||
module ActionController
|
||||
# TODO: Review explicit to see if they will automatically be handled by
|
||||
|
||||
@@ -2,17 +2,6 @@ require 'stringio'
|
||||
require 'uri'
|
||||
require 'active_support/test_case'
|
||||
|
||||
# Monkey patch Rack::Lint to support rewind
|
||||
module Rack
|
||||
class Lint
|
||||
class InputWrapper
|
||||
def rewind
|
||||
@input.rewind
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
module ActionController
|
||||
module Integration #:nodoc:
|
||||
# An integration Session instance represents a set of requests and responses
|
||||
|
||||
@@ -32,6 +32,8 @@ module ActionController
|
||||
else
|
||||
@klass.to_s.constantize
|
||||
end
|
||||
rescue NameError
|
||||
@klass
|
||||
end
|
||||
|
||||
def active?
|
||||
|
||||
22
actionpack/lib/action_controller/rack_ext.rb
Normal file
22
actionpack/lib/action_controller/rack_ext.rb
Normal file
@@ -0,0 +1,22 @@
|
||||
module Rack
|
||||
module Utils
|
||||
module Multipart
|
||||
class << self
|
||||
def parse_multipart_with_rewind(env)
|
||||
result = parse_multipart_without_rewind(env)
|
||||
|
||||
begin
|
||||
env['rack.input'].rewind if env['rack.input'].respond_to?(:rewind)
|
||||
rescue Errno::ESPIPE
|
||||
# Handles exceptions raised by input streams that cannot be rewound
|
||||
# such as when using plain CGI under Apache
|
||||
end
|
||||
|
||||
result
|
||||
end
|
||||
|
||||
alias_method_chain :parse_multipart, :rewind
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -15,15 +15,19 @@ module ActionController
|
||||
@io.rewind
|
||||
end
|
||||
|
||||
def string
|
||||
@string
|
||||
end
|
||||
|
||||
def method_missing(method, *args, &block)
|
||||
@io.send(method, *args, &block)
|
||||
end
|
||||
|
||||
private
|
||||
def read_original_io
|
||||
unless @str
|
||||
@str = @io.read
|
||||
@io = StringIO.new(@str)
|
||||
unless @string
|
||||
@string = @io.read
|
||||
@io = StringIO.new(@string)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -200,7 +200,7 @@ class MultipartParamsParsingTest < ActionController::IntegrationTest
|
||||
def with_muck_middleware
|
||||
original_middleware = ActionController::Dispatcher.middleware
|
||||
middleware = original_middleware.dup
|
||||
middleware.use MuckMiddleware
|
||||
middleware.insert_after ActionController::RewindableInput, MuckMiddleware
|
||||
ActionController::Dispatcher.middleware = middleware
|
||||
yield
|
||||
ActionController::Dispatcher.middleware = original_middleware
|
||||
|
||||
@@ -183,7 +183,7 @@ class UrlEncodedParamsParsingTest < ActionController::IntegrationTest
|
||||
def with_muck_middleware
|
||||
original_middleware = ActionController::Dispatcher.middleware
|
||||
middleware = original_middleware.dup
|
||||
middleware.use MuckMiddleware
|
||||
middleware.insert_after ActionController::RewindableInput, MuckMiddleware
|
||||
ActionController::Dispatcher.middleware = middleware
|
||||
yield
|
||||
ActionController::Dispatcher.middleware = original_middleware
|
||||
|
||||
Reference in New Issue
Block a user