diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-07-19 17:16:28 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-07-19 17:16:28 +0300 |
commit | e4384360a16dd9a19d4d2d25d0ef1f2b862ed2a6 (patch) | |
tree | 2fcdfa7dcdb9db8f5208b2562f4b4e803d671243 /config/initializers/action_dispatch_journey_router.rb | |
parent | ffda4e7bcac36987f936b4ba515995a6698698f0 (diff) |
Add latest changes from gitlab-org/gitlab@16-2-stable-eev16.2.0-rc42
Diffstat (limited to 'config/initializers/action_dispatch_journey_router.rb')
-rw-r--r-- | config/initializers/action_dispatch_journey_router.rb | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/config/initializers/action_dispatch_journey_router.rb b/config/initializers/action_dispatch_journey_router.rb new file mode 100644 index 00000000000..14f5ee367a6 --- /dev/null +++ b/config/initializers/action_dispatch_journey_router.rb @@ -0,0 +1,51 @@ +# frozen_string_literal: true + +module ActionDispatch + module Journey + class Router + private + + # Besides the patch, this method is a duplicate for the original method defined in Rails: + # https://github.com/rails/rails/blob/v7.0.5/actionpack/lib/action_dispatch/journey/router.rb#L109-L132 + # See https://github.com/rails/rails/issues/47244 + def find_routes(req) + path_info = req.path_info + routes = filter_routes(path_info).concat custom_routes.find_all { |r| + r.path.match?(path_info) + } + + if req.head? + routes = match_head_routes(routes, req) + else + routes.select! { |r| r.matches?(req) } + end + + routes.sort_by!(&:precedence) + + routes.map! do |r| + match_data = r.path.match(path_info) + path_parameters = {} + + # This is the patch we are adding. This handles routes where `r.matches?` above is true + # but the route does not actually match due to other constraints + # + # Without this line the following error is raised: + # + # NoMethodError: + # undefined method `names' for nil:NilClass + # + # The behavior is covered by spec/initializers/action_dispatch_journey_router_spec.rb + next if match_data.nil? + + match_data.names.each_with_index do |name, i| + val = match_data[i + 1] + path_parameters[name.to_sym] = Utils.unescape_uri(val) if val + end + [match_data, path_parameters, r] + end.compact! + + routes + end + end + end +end |