Skip to content

Commit

Permalink
avoid executing filters even if prefix matches with other namespace
Browse files Browse the repository at this point in the history
Fixes #1251
  • Loading branch information
namusyaka committed Feb 9, 2017
1 parent 32f416c commit 2d172e5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion sinatra-contrib/lib/sinatra/namespace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ def prefixed_path(a, b)
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
Expand Down
31 changes: 31 additions & 0 deletions sinatra-contrib/spec/namespace_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -787,5 +787,36 @@ class CError < StandardError;
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

0 comments on commit 2d172e5

Please sign in to comment.