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

avoid executing filters even if prefix matched with other namespace #1253

Merged
merged 1 commit into from
Mar 27, 2017
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
avoid executing filters even if prefix matches with other namespace
Fixes #1251
  • Loading branch information
namusyaka committed Feb 9, 2017
commit 2d172e5c735a25f1c4852dfc81d784b0a61f0369
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