Skip to content

Commit

Permalink
Compare route paths using regex not start_with to fix edge cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
gregschmit committed Jan 6, 2023
1 parent f9ff9b5 commit a3cea75
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/rest_framework/utils.rb
Expand Up @@ -79,7 +79,7 @@ def self.get_routes(application_routes, request, current_route: nil)
current_route ||= self.get_request_route(application_routes, request)
current_path = current_route.path.spec.to_s.gsub("(.:format)", "")
current_levels = current_path.count("/")
current_comparable_path = self.comparable_path(current_path)
current_comparable_path = %r{^#{Regexp.quote(self.comparable_path(current_path))}(/|$)}

# Add helpful properties of the current route.
path_args = current_route.required_parts.map { |n| request.path_parameters[n] }
Expand All @@ -96,7 +96,7 @@ def self.get_routes(application_routes, request, current_route: nil)
# to show.
(
(r.defaults[:subdomain].blank? || r.defaults[:subdomain] == request.subdomain) &&
self.comparable_path(r.path.spec.to_s).start_with?(current_comparable_path) &&
current_comparable_path.match?(self.comparable_path(r.path.spec.to_s)) &&
r.defaults[:controller].present? &&
r.defaults[:action].present?
)
Expand Down

0 comments on commit a3cea75

Please sign in to comment.