summaryrefslogtreecommitdiff
path: root/lib/gitlab/routing.rb
diff options
context:
space:
mode:
authorBob Van Landuyt <bob@vanlanduyt.co>2017-10-27 11:29:51 +0200
committerBob Van Landuyt <bob@vanlanduyt.co>2017-11-07 19:52:09 +0100
commit58d1d6a5c7e0a45c9aa8a9d4d1be24dbdce5a08a (patch)
tree4f78e39630276f4dc734964f44dc1d7869282955 /lib/gitlab/routing.rb
parent5dde0536c323d14fef2327a8d553b5f8a8a7b2d0 (diff)
downloadgitlab-ce-58d1d6a5c7e0a45c9aa8a9d4d1be24dbdce5a08a.tar.gz
Free up some group reserved words
Diffstat (limited to 'lib/gitlab/routing.rb')
-rw-r--r--lib/gitlab/routing.rb10
1 files changed, 9 insertions, 1 deletions
diff --git a/lib/gitlab/routing.rb b/lib/gitlab/routing.rb
index abfd413b7ea..defb47663cb 100644
--- a/lib/gitlab/routing.rb
+++ b/lib/gitlab/routing.rb
@@ -42,10 +42,18 @@ module Gitlab
end
def self.redirect_legacy_paths(router, *paths)
+ build_redirect_path = lambda do |request, _params, path|
+ # Only replace the last occurence of `path`.
+ path = request.fullpath.sub(%r{/#{path}/*(?!.*#{path})}, "/-/#{path}/")
+ path << request.query_string if request.query_string.present?
+
+ path
+ end
+
paths.each do |path|
router.match "/#{path}(/*rest)",
via: [:get, :post, :patch, :delete],
- to: router.redirect { |_params, request| request.fullpath.gsub(%r{/#{path}/*}, "/-/#{path}/") },
+ to: router.redirect { |params, request| build_redirect_path.call(request, params, path) },
as: "legacy_#{path}_redirect"
end
end