Merge pull request #13999 from jamox/update_rack

This updates rails to use edge rack
This commit is contained in:
Aaron Patterson 2014-07-08 11:46:56 -07:00
commit 97d62a32f8
7 changed files with 34 additions and 22 deletions

View File

@ -7,6 +7,7 @@ gemspec
# ensure correct loading order
gem 'mocha', '~> 0.14', require: false
gem 'rack', github: 'rack/rack'
gem 'rack-cache', '~> 1.2'
gem 'jquery-rails', '~> 3.1.0'
gem 'turbolinks'

View File

@ -21,7 +21,7 @@ Gem::Specification.new do |s|
s.add_dependency 'activesupport', version
s.add_dependency 'rack', '~> 1.5.2'
s.add_dependency 'rack', '~> 1.6.0.alpha'
s.add_dependency 'rack-test', '~> 0.6.2'
s.add_dependency 'actionview', version

View File

@ -54,8 +54,14 @@ module ActionDispatch
end
def formats
@env["action_dispatch.request.formats"] ||=
if parameters[:format]
@env["action_dispatch.request.formats"] ||= begin
params_readable = begin
parameters[:format]
rescue ActionController::BadRequest
false
end
if params_readable
Array(Mime[parameters[:format]])
elsif use_accept_header && valid_accept_header
accepts
@ -64,8 +70,8 @@ module ActionDispatch
else
[Mime::HTML]
end
end
end
# Sets the \variant for template.
def variant=(variant)
if variant.is_a?(Symbol)

View File

@ -42,23 +42,16 @@ module ActionDispatch
private
# Convert nested Hash to HashWithIndifferentAccess
# and UTF-8 encode both keys and values in nested Hash.
# Convert nested Hash to HashWithIndifferentAccess.
#
# TODO: Validate that the characters are UTF-8. If they aren't,
# you'll get a weird error down the road, but our form handling
# should really prevent that from happening
def normalize_encode_params(params)
case params
when String
params.force_encoding(Encoding::UTF_8).encode!
when Hash
if params.has_key?(:tempfile)
UploadedFile.new(params)
else
params.each_with_object({}) do |(key, val), new_hash|
new_key = key.is_a?(String) ? key.dup.force_encoding(Encoding::UTF_8).encode! : key
new_hash[new_key] = if val.is_a?(Array)
new_hash[key] = if val.is_a?(Array)
val.map! { |el| normalize_encode_params(el) }
else
normalize_encode_params(val)

View File

@ -8,7 +8,11 @@ class MultipartParamsParsingTest < ActionDispatch::IntegrationTest
end
def parse
self.class.last_request_parameters = request.request_parameters
self.class.last_request_parameters = begin
request.request_parameters
rescue EOFError
{}
end
self.class.last_parameters = request.parameters
head :ok
end

View File

@ -798,6 +798,12 @@ class RequestFormat < BaseRequestTest
assert_not request.format.json?
end
test "format does not throw exceptions when malformed parameters" do
request = stub_request("QUERY_STRING" => "x[y]=1&x[y][][w]=2")
assert request.formats
assert request.format.html?
end
test "formats with xhr request" do
request = stub_request 'HTTP_X_REQUESTED_WITH' => "XMLHttpRequest"
request.expects(:parameters).at_least_once.returns({})
@ -893,15 +899,15 @@ class RequestParameters < BaseRequestTest
assert_equal({"bar" => 2}, request.query_parameters)
end
test "parameters still accessible after rack parse error" do
test "parameters not accessible after rack parse error" do
request = stub_request("QUERY_STRING" => "x[y]=1&x[y][][w]=2")
assert_raises(ActionController::BadRequest) do
# rack will raise a TypeError when parsing this query string
request.parameters
2.times do
assert_raises(ActionController::BadRequest) do
# rack will raise a TypeError when parsing this query string
request.parameters
end
end
assert_equal({}, request.parameters)
end
test "we have access to the original exception" do

View File

@ -203,10 +203,12 @@ module Rails
def rails_gemfile_entry
if options.dev?
[GemfileEntry.path('rails', Rails::Generators::RAILS_DEV_PATH),
GemfileEntry.github('arel', 'rails/arel')]
GemfileEntry.github('arel', 'rails/arel'),
GemfileEntry.github('rack', 'rack/rack')]
elsif options.edge?
[GemfileEntry.github('rails', 'rails/rails'),
GemfileEntry.github('arel', 'rails/arel')]
GemfileEntry.github('arel', 'rails/arel'),
GemfileEntry.github('rack', 'rack/rack')]
else
[GemfileEntry.version('rails',
Rails::VERSION::STRING,