Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Kozono <mkozono@gmail.com>2017-05-18 22:56:39 +0300
committerMichael Kozono <mkozono@gmail.com>2017-05-19 02:24:10 +0300
commitf9785dcec34c4205732871523f95b9743db00965 (patch)
tree4fccd9b776c98371e2e5e434d85ea1bfe7f3c1ac /app/controllers
parent11f82de1efc087ee812764764e31161347e593cb (diff)
Fix ensure_canonical_path for top level routes
Don’t replace a substring of the path if it is part of the top level route. E.g. When redirecting from `/groups/ups` to `/groups/foo`, be careful not to do `/grofoo/ups`. Projects are unaffected by this issue, but I am grouping the `#ensure_canonical_path` tests similar to the group and user tests.
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/concerns/routable_actions.rb22
1 files changed, 17 insertions, 5 deletions
diff --git a/app/controllers/concerns/routable_actions.rb b/app/controllers/concerns/routable_actions.rb
index 76c2908463c..a5b793081b2 100644
--- a/app/controllers/concerns/routable_actions.rb
+++ b/app/controllers/concerns/routable_actions.rb
@@ -24,15 +24,27 @@ module RoutableActions
end
end
- def ensure_canonical_path(routable, requested_path)
+ def ensure_canonical_path(routable, requested_full_path)
return unless request.get?
canonical_path = routable.full_path
- if canonical_path != requested_path
- if canonical_path.casecmp(requested_path) != 0
- flash[:notice] = "#{routable.class.to_s.titleize} '#{requested_path}' was moved to '#{canonical_path}'. Please update any links and bookmarks that may still have the old path."
+ if canonical_path != requested_full_path
+ if canonical_path.casecmp(requested_full_path) != 0
+ flash[:notice] = "#{routable.class.to_s.titleize} '#{requested_full_path}' was moved to '#{canonical_path}'. Please update any links and bookmarks that may still have the old path."
end
- redirect_to request.original_fullpath.sub(requested_path, canonical_path)
+ redirect_to full_canonical_path(canonical_path, requested_full_path)
+ end
+ end
+
+ def full_canonical_path(canonical_path, requested_full_path)
+ request_path = request.original_fullpath
+ top_level_route_regex = %r{\A(/#{Regexp.union(DynamicPathValidator::TOP_LEVEL_ROUTES)}/)#{requested_full_path}}
+ top_level_route_match = request_path.match(top_level_route_regex)
+
+ if top_level_route_match
+ request_path.sub(top_level_route_regex, "\\1#{canonical_path}")
+ else
+ request_path.sub(requested_full_path, canonical_path)
end
end
end