catch empty routes
This fixes a bug where an empty route would catch all requests resulting in all routes found with the empty route.
This commit is contained in:
parent
27442f4061
commit
335dbdd487
|
@ -40,7 +40,7 @@ module Zero
|
||||||
routes.each do |route, target|
|
routes.each do |route, target|
|
||||||
@routes[
|
@routes[
|
||||||
Regexp.new(
|
Regexp.new(
|
||||||
route.gsub(VARIABLE_MATCH, VARIABLE_REGEX) + '$')] = target
|
'^' + route.gsub(VARIABLE_MATCH, VARIABLE_REGEX) + '$')] = target
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,13 @@ describe Zero::Router, '#call' do
|
||||||
it_behaves_like "a sample app"
|
it_behaves_like "a sample app"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'with empty path' do
|
||||||
|
let(:routes) {{ '' => wrong_app, '/welcome' => app }}
|
||||||
|
let(:env) { EnvGenerator.get('/welcome') }
|
||||||
|
|
||||||
|
it_behaves_like "a sample app"
|
||||||
|
end
|
||||||
|
|
||||||
context 'with multiple router' do
|
context 'with multiple router' do
|
||||||
let(:routes) {{ '/foo' => app, '/wrong' => wrong_app }}
|
let(:routes) {{ '/foo' => app, '/wrong' => wrong_app }}
|
||||||
let(:env) { EnvGenerator.get('/foo') }
|
let(:env) { EnvGenerator.get('/foo') }
|
||||||
|
@ -45,6 +52,14 @@ describe Zero::Router, '#call' do
|
||||||
it_behaves_like "a sample app"
|
it_behaves_like "a sample app"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'with empty route' do
|
||||||
|
let(:routes) {{ '' => wrong_app }}
|
||||||
|
let(:env) { EnvGenerator.get('/foo') }
|
||||||
|
let(:result) { ['Not found!'] }
|
||||||
|
let(:status_code) { 404 }
|
||||||
|
it_behaves_like "a sample app"
|
||||||
|
end
|
||||||
|
|
||||||
context 'with parameters' do
|
context 'with parameters' do
|
||||||
let(:routes) {{ '/foo/:id' => app }}
|
let(:routes) {{ '/foo/:id' => app }}
|
||||||
let(:env) { EnvGenerator.get('/foo/bar') }
|
let(:env) { EnvGenerator.get('/foo/bar') }
|
||||||
|
|
Loading…
Reference in New Issue