mirror of
https://github.com/sinatra/sinatra
synced 2023-03-27 23:18:01 -04:00
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
2 changed files with 25 additions and 1 deletions
|
@ -1089,7 +1089,12 @@ module Sinatra
|
|||
|
||||
# Dispatch a request with error handling.
|
||||
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
|
||||
static! if settings.static? && (request.get? || request.head?)
|
||||
|
|
|
@ -78,4 +78,23 @@ class MiddlewareTest < Minitest::Test
|
|||
@app.use FreezeMiddleware
|
||||
get '/Foo'
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue