Skip to content

Commit

Permalink
avoid FrozenError when params contains frozen value
Browse files Browse the repository at this point in the history
The error can be fixed by using dupped values.
The original code for testing is implemented by @programmarchy in #1479

Fixes #1478
Closes #1479
  • Loading branch information
namusyaka committed Dec 15, 2018
1 parent 5d3099e commit c686a10
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/sinatra/base.rb
Expand Up @@ -1089,7 +1089,7 @@ def invoke

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

invoke do
static! if settings.static? && (request.get? || request.head?)
Expand Down
13 changes: 13 additions & 0 deletions test/middleware_test.rb
Expand Up @@ -65,4 +65,17 @@ def call(env)
assert_equal "/FOO", body
assert_equal "UpcaseMiddleware", response['X-Tests']
end

class FreezeMiddleware < MockMiddleware
def call(env)
req = Rack::Request.new(env)
req.update_param('bar', 'baz'.freeze)
super
end
end

it "works when middleware adds a frozen param" do
@app.use FreezeMiddleware
get '/Foo'
end
end

0 comments on commit c686a10

Please sign in to comment.