Merge pull request #1517 from segiddins/segiddins/nil-param

Avoid `TypeError` when params contain a key without a value on Ruby < 2.4
This commit is contained in:
namusyaka 2019-02-08 01:21:54 +09:00 committed by GitHub
commit 2e36823823
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 1 deletions

View File

@ -1,3 +1,7 @@
## Unreleased
* Avoid `TypeError` when params contain a key without a value on Ruby < 2.4 [#1516](https://github.com/sinatra/sinatra/pull/1516) by Samuel Giddins
## 2.0.5 / 2018-12-22
* Avoid FrozenError when params contains frozen value [#1506](https://github.com/sinatra/sinatra/pull/1506) by Kunpei Sakai

View File

@ -1089,7 +1089,7 @@ module Sinatra
# Dispatch a request with error handling.
def dispatch!
@params.merge!(@request.params).each { |key, val| @params[key] = force_encoding(val.dup) }
@params.merge!(@request.params).each { |key, val| @params[key] = val && force_encoding(val.dup) }
invoke do
static! if settings.static? && (request.get? || request.head?)

View File

@ -311,6 +311,17 @@ class RoutingTest < Minitest::Test
assert_equal 'well, alright', body
end
it "handles params without a value" do
mock_app {
get '/' do
assert_nil params.fetch('foo')
"Given: #{params.keys.sort.join(',')}"
end
}
get '/?foo'
assert_equal 'Given: foo', body
end
it "merges named params and query string params in params" do
mock_app {
get '/:foo' do