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:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-06-18 14:18:50 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-06-18 14:18:50 +0300
commit8c7f4e9d5f36cff46365a7f8c4b9c21578c1e781 (patch)
treea77e7fe7a93de11213032ed4ab1f33a3db51b738 /lib/gitlab/routing.rb
parent00b35af3db1abfe813a778f643dad221aad51fca (diff)
Add latest changes from gitlab-org/gitlab@13-1-stable-ee
Diffstat (limited to 'lib/gitlab/routing.rb')
-rw-r--r--lib/gitlab/routing.rb42
1 files changed, 31 insertions, 11 deletions
diff --git a/lib/gitlab/routing.rb b/lib/gitlab/routing.rb
index 84885be9bda..cad127922df 100644
--- a/lib/gitlab/routing.rb
+++ b/lib/gitlab/routing.rb
@@ -4,6 +4,36 @@ module Gitlab
module Routing
extend ActiveSupport::Concern
+ class LegacyRedirector
+ # @params path_type [symbol] type of path to do "-" redirection
+ # https://gitlab.com/gitlab-org/gitlab/-/issues/16854
+ def initialize(path_type)
+ @path_type = path_type
+ end
+
+ def call(_params, request)
+ ensure_valid_uri!(request)
+
+ # Only replace the last occurrence of `path`.
+ #
+ # `request.fullpath` includes the querystring
+ new_path = request.path.sub(%r{/#{@path_type}(/*)(?!.*#{@path_type})}, "/-/#{@path_type}\\1")
+ new_path = "#{new_path}?#{request.query_string}" if request.query_string.present?
+
+ new_path
+ end
+
+ private
+
+ def ensure_valid_uri!(request)
+ URI.parse(request.path)
+ rescue URI::InvalidURIError => e
+ # If url is invalid, raise custom error,
+ # which can be ignored by monitoring tools.
+ raise ActionController::RoutingError.new(e.message)
+ end
+ end
+
mattr_accessor :_includers
self._includers = []
@@ -44,20 +74,10 @@ module Gitlab
end
def self.redirect_legacy_paths(router, *paths)
- build_redirect_path = lambda do |request, _params, path|
- # Only replace the last occurrence of `path`.
- #
- # `request.fullpath` includes the querystring
- new_path = request.path.sub(%r{/#{path}(/*)(?!.*#{path})}, "/-/#{path}\\1")
- new_path = "#{new_path}?#{request.query_string}" if request.query_string.present?
-
- new_path
- end
-
paths.each do |path|
router.match "/#{path}(/*rest)",
via: [:get, :post, :patch, :delete],
- to: router.redirect { |params, request| build_redirect_path.call(request, params, path) },
+ to: router.redirect(LegacyRedirector.new(path)),
as: "legacy_#{path}_redirect"
end
end