1
0
Fork 0
mirror of https://github.com/sinatra/sinatra synced 2023-03-27 23:18:01 -04:00

Merge pull request #1390 from iguchi1124/fix-captured-paths

Fix to ignore empty captures from params
This commit is contained in:
namusyaka 2018-02-21 23:29:23 +09:00 committed by GitHub
commit 05cb1fe2fe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 1 deletions

View file

@ -1029,7 +1029,7 @@ module Sinatra
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

View file

@ -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