Skip to content

Commit

Permalink
Support nil param on Ruby < 2.4
Browse files Browse the repository at this point in the history
  • Loading branch information
segiddins committed Jan 16, 2019
1 parent 26fa5c8 commit d8c1839
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/sinatra/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1089,7 +1089,7 @@ def invoke

# 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?)
Expand Down
11 changes: 11 additions & 0 deletions test/routing_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d8c1839

Please sign in to comment.