Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix to ignore empty captures from params #1390

Merged
merged 2 commits into from
Feb 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/sinatra/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1029,7 +1029,7 @@ def process_route(pattern, conditions, block = nil, values = [])
if regexp_exists
captures = pattern.match(route).captures
values += captures
@params[:captures] = captures
@params[:captures] = captures unless captures.nil? || captures.empty?
else
values += params.values.flatten
end
Expand Down
15 changes: 15 additions & 0 deletions test/routing_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,21 @@ class RoutingTest < Minitest::Test
assert_equal "This is not a drill either", response.body
end

it "returns empty when unmatched with any regex captures" do
mock_app do
before do
# noop
end

get '/hello' do
params.to_s
end
end

assert get('/hello').ok?
assert_body '{}'
end

it "uses 404 error handler for not matching route" do
mock_app {
not_found do
Expand Down