Allow changing request.path_info in a before filter that has a pattern. Fixes #114.
This commit is contained in:
parent
aa06ed5e6d
commit
4988126624
|
@ -28,6 +28,18 @@ module Sinatra
|
||||||
else
|
else
|
||||||
alias secure? ssl?
|
alias secure? ssl?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def route
|
||||||
|
@route ||= begin
|
||||||
|
path = Rack::Utils.unescape(path_info)
|
||||||
|
path.empty? ? "/" : path
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def path_info=(value)
|
||||||
|
@route = nil
|
||||||
|
super
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# The response object. See Rack::Response and Rack::ResponseHelpers for
|
# The response object. See Rack::Response and Rack::ResponseHelpers for
|
||||||
|
@ -635,11 +647,7 @@ module Sinatra
|
||||||
# Returns pass block.
|
# Returns pass block.
|
||||||
def process_route(pattern, keys, conditions)
|
def process_route(pattern, keys, conditions)
|
||||||
@original_params ||= @params
|
@original_params ||= @params
|
||||||
@path ||= begin
|
if match = pattern.match(@request.route)
|
||||||
path = unescape(@request.path_info)
|
|
||||||
path.empty? ? "/" : path
|
|
||||||
end
|
|
||||||
if match = pattern.match(@path)
|
|
||||||
values = match.captures.to_a
|
values = match.captures.to_a
|
||||||
params =
|
params =
|
||||||
if keys.any?
|
if keys.any?
|
||||||
|
|
|
@ -255,6 +255,16 @@ class AfterFilterTest < Test::Unit::TestCase
|
||||||
assert ran_filter
|
assert ran_filter
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'changes to path_info from a pattern matching before filter are respoected when routing' do
|
||||||
|
mock_app do
|
||||||
|
before('/foo') { request.path_info = '/bar' }
|
||||||
|
get('/bar') { 'blah' }
|
||||||
|
end
|
||||||
|
get '/foo'
|
||||||
|
assert ok?
|
||||||
|
assert_equal 'blah', body
|
||||||
|
end
|
||||||
|
|
||||||
it 'generates block arguments from route pattern' do
|
it 'generates block arguments from route pattern' do
|
||||||
subpath = nil
|
subpath = nil
|
||||||
mock_app do
|
mock_app do
|
||||||
|
|
Loading…
Reference in New Issue