Skip to content

Commit

Permalink
Merge pull request #1390 from iguchi1124/fix-captured-paths
Browse files Browse the repository at this point in the history
Fix to ignore empty captures from params
  • Loading branch information
namusyaka authored Feb 21, 2018
2 parents 3d26361 + 06f8c83 commit 05cb1fe
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
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

0 comments on commit 05cb1fe

Please sign in to comment.