Skip to content

Commit

Permalink
Don't remove the trailing slash from PATH_INFO
Browse files Browse the repository at this point in the history
normalize_path removed trailing slash from the PATH_INFO - this may be
good for normalization, but we should probably not mess up with original
parameters - if developers need normalized paths, they should do it by
themselves.

Instead, just normalize path_info for recognition.
  • Loading branch information
drogus committed Oct 6, 2012
1 parent 850267e commit e19a702
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
10 changes: 6 additions & 4 deletions lib/journey/router.rb
Expand Up @@ -51,7 +51,7 @@ def initialize routes, options
end end


def call env def call env
env['PATH_INFO'] = Utils.normalize_path env['PATH_INFO'] env['PATH_INFO'] = Utils.normalize_path env['PATH_INFO'], false


find_routes(env).each do |match, parameters, route| find_routes(env).each do |match, parameters, route|
script_name, path_info, set_params = env.values_at('SCRIPT_NAME', script_name, path_info, set_params = env.values_at('SCRIPT_NAME',
Expand Down Expand Up @@ -125,8 +125,10 @@ def filter_routes path
def find_routes env def find_routes env
req = request_class.new env req = request_class.new env


routes = filter_routes(req.path_info).concat custom_routes.find_all { |r| path_info = Utils.normalize_path(req.path_info)
r.path.match(req.path_info)
routes = filter_routes(path_info).concat custom_routes.find_all { |r|
r.path.match(path_info)
} }
routes.concat get_routes_as_head(routes) routes.concat get_routes_as_head(routes)


Expand All @@ -137,7 +139,7 @@ def find_routes env
routes.reject! { |r| req.ip && !(r.ip === req.ip) } routes.reject! { |r| req.ip && !(r.ip === req.ip) }


routes.map! { |r| routes.map! { |r|
match_data = r.path.match(req.path_info) match_data = r.path.match(path_info)
match_names = match_data.names.map { |n| n.to_sym } match_names = match_data.names.map { |n| n.to_sym }
match_values = match_data.captures.map { |v| v && Utils.unescape_uri(v) } match_values = match_data.captures.map { |v| v && Utils.unescape_uri(v) }
info = Hash[match_names.zip(match_values).find_all { |_,y| y }] info = Hash[match_names.zip(match_values).find_all { |_,y| y }]
Expand Down
4 changes: 2 additions & 2 deletions lib/journey/router/utils.rb
Expand Up @@ -11,10 +11,10 @@ class Utils
# normalize_path("/foo/") # => "/foo" # normalize_path("/foo/") # => "/foo"
# normalize_path("foo") # => "/foo" # normalize_path("foo") # => "/foo"
# normalize_path("") # => "/" # normalize_path("") # => "/"
def self.normalize_path(path) def self.normalize_path(path, remove_trailing_slash = true)
path = "/#{path}" path = "/#{path}"
path.squeeze!('/') path.squeeze!('/')
path.sub!(%r{/+\Z}, '') path.sub!(%r{/+\Z}, '') if remove_trailing_slash
path = '/' if path == '' path = '/' if path == ''
path path
end end
Expand Down

0 comments on commit e19a702

Please sign in to comment.