diff options
author | Michael Kozono <mkozono@gmail.com> | 2017-05-18 16:23:05 -0700 |
---|---|---|
committer | Michael Kozono <mkozono@gmail.com> | 2017-05-19 09:13:27 -0700 |
commit | 49697bc8df613dfe8e88f5f7cd8eae57e26c786f (patch) | |
tree | da5888be64878d8b35d1727dc802d609960fd631 /app/controllers/concerns/routable_actions.rb | |
parent | f9785dcec34c4205732871523f95b9743db00965 (diff) | |
download | gitlab-ce-49697bc8df613dfe8e88f5f7cd8eae57e26c786f.tar.gz |
Refactor to more robust implementationfix-issue-32506
In order to avoid string manipulation or modify route params (to make them unambiguous for `url_for`), we are accepting a behavior change:
When being redirected to the canonical path for a group, if you requested a group show path starting with `/groups/…` then you’ll now be redirected to the group at root `/…`.
Diffstat (limited to 'app/controllers/concerns/routable_actions.rb')
-rw-r--r-- | app/controllers/concerns/routable_actions.rb | 14 |
1 files changed, 1 insertions, 13 deletions
diff --git a/app/controllers/concerns/routable_actions.rb b/app/controllers/concerns/routable_actions.rb index a5b793081b2..4199da9cdf5 100644 --- a/app/controllers/concerns/routable_actions.rb +++ b/app/controllers/concerns/routable_actions.rb @@ -32,19 +32,7 @@ module RoutableActions 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 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) + redirect_to build_canonical_path(routable) end end end |