Permalink
Browse files

Don't remove the trailing slash from PATH_INFO

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 5, 2012
1 parent 850267e commit e19a702944fff6737c7c0d8bca636dfecb32bbd2
Showing with 8 additions and 6 deletions.
  1. +6 −4 lib/journey/router.rb
  2. +2 −2 lib/journey/router/utils.rb
View
@@ -51,7 +51,7 @@ def initialize routes, options
end
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|
script_name, path_info, set_params = env.values_at('SCRIPT_NAME',
@@ -125,8 +125,10 @@ def filter_routes path
def find_routes env
req = request_class.new env
- routes = filter_routes(req.path_info).concat custom_routes.find_all { |r|
- r.path.match(req.path_info)
+ path_info = Utils.normalize_path(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)
@@ -137,7 +139,7 @@ def find_routes env
routes.reject! { |r| req.ip && !(r.ip === req.ip) }
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_values = match_data.captures.map { |v| v && Utils.unescape_uri(v) }
info = Hash[match_names.zip(match_values).find_all { |_,y| y }]
@@ -11,10 +11,10 @@ class Utils
# normalize_path("/foo/") # => "/foo"
# normalize_path("foo") # => "/foo"
# normalize_path("") # => "/"
- def self.normalize_path(path)
+ def self.normalize_path(path, remove_trailing_slash = true)
path = "/#{path}"
path.squeeze!('/')
- path.sub!(%r{/+\Z}, '')
+ path.sub!(%r{/+\Z}, '') if remove_trailing_slash
path = '/' if path == ''
path
end

0 comments on commit e19a702

Please sign in to comment.