Skip to content

Commit

Permalink
avoid multiple errors even if params contains special values
Browse files Browse the repository at this point in the history
The original fixes are #1506 and #1517.
This commit considers `FrozenError` and `TypeEror` for the case.
  • Loading branch information
namusyaka committed Apr 11, 2019
1 parent 7b7043c commit 070e3cc
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/sinatra/base.rb
Expand Up @@ -1089,7 +1089,14 @@ def invoke

# Dispatch a request with error handling.
def dispatch!
@params.merge!(@request.params).each { |key, val| @params[key] = val && force_encoding(val.dup) }
@params.merge!(@request.params).each do |key, val|
@params[key] =
begin
force_encoding(val.dup)
rescue TypeError
val
end
end

invoke do
static! if settings.static? && (request.get? || request.head?)
Expand Down
19 changes: 19 additions & 0 deletions test/middleware_test.rb
Expand Up @@ -78,4 +78,23 @@ def call(env)
@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

0 comments on commit 070e3cc

Please sign in to comment.