avoid multiple errors even if `params` contains special values
The original fixes are #1506 and #1517. This commit considers `FrozenError` and `TypeEror` for the case.
This commit is contained in:
parent
7b7043cde3
commit
a5429833e4
|
@ -1089,7 +1089,12 @@ module Sinatra
|
||||||
|
|
||||||
# Dispatch a request with error handling.
|
# Dispatch a request with error handling.
|
||||||
def dispatch!
|
def dispatch!
|
||||||
@params.merge!(@request.params).each { |key, val| @params[key] = val && force_encoding(val.dup) }
|
# Avoid passing frozen string in force_encoding
|
||||||
|
@params.merge!(@request.params).each do |key, val|
|
||||||
|
next unless val.respond_to?(:force_encoding)
|
||||||
|
val = val.dup if val.frozen?
|
||||||
|
@params[key] = force_encoding(val)
|
||||||
|
end
|
||||||
|
|
||||||
invoke do
|
invoke do
|
||||||
static! if settings.static? && (request.get? || request.head?)
|
static! if settings.static? && (request.get? || request.head?)
|
||||||
|
|
|
@ -78,4 +78,23 @@ class MiddlewareTest < Minitest::Test
|
||||||
@app.use FreezeMiddleware
|
@app.use FreezeMiddleware
|
||||||
get '/Foo'
|
get '/Foo'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class SpecialConstsMiddleware < MockMiddleware
|
||||||
|
def call(env)
|
||||||
|
req = Rack::Request.new(env)
|
||||||
|
req.update_param('s', :s)
|
||||||
|
req.update_param('i', 1)
|
||||||
|
req.update_param('c', 3.to_c)
|
||||||
|
req.update_param('t', true)
|
||||||
|
req.update_param('f', false)
|
||||||
|
req.update_param('n', nil)
|
||||||
|
super
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
it "handles params when the params contains true/false values" do
|
||||||
|
@app.use SpecialConstsMiddleware
|
||||||
|
get '/'
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue