Merge pull request #1253 from namusyaka/fix-1251

avoid executing filters even if prefix matched with other namespace
This commit is contained in:
Zachary Scott 2017-03-28 08:49:03 +09:00 committed by GitHub
commit 69a7b8f233
2 changed files with 32 additions and 1 deletions

View File

@ -333,7 +333,7 @@ module Sinatra
end
def prefixed(method, pattern = nil, conditions = {}, &block)
default = /.*/ if method == :before or method == :after
default = %r{(?:/.*)?} if method == :before or method == :after
pattern, conditions = compile pattern, conditions, default
result = base.send(method, pattern, conditions, &block)
invoke_hook :route_added, method.to_s.upcase, pattern, block

View File

@ -787,5 +787,36 @@ describe Sinatra::Namespace do
expect(get('/foo/bar').status).to eq(200)
expect(last_response.body).to eq('true')
end
it 'avoids executing filters even if prefix matches with other namespace' do
mock_app do
helpers do
def dump_args(*args)
args.inspect
end
end
namespace '/foo' do
helpers do
def dump_args(*args)
super(:foo, *args)
end
end
get('') { dump_args }
end
namespace '/foo-bar' do
helpers do
def dump_args(*args)
super(:foo_bar, *args)
end
end
get('') { dump_args }
end
end
get '/foo-bar'
expect(last_response.body).to eq('[:foo_bar]')
end
end
end