From a3cea752987db8277bbbb24a005777774f47bdb0 Mon Sep 17 00:00:00 2001 From: "Gregory N. Schmit" Date: Thu, 5 Jan 2023 18:22:09 -0600 Subject: [PATCH] Compare route paths using regex not start_with to fix edge cases. --- lib/rest_framework/utils.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/rest_framework/utils.rb b/lib/rest_framework/utils.rb index 1a947b0..707a357 100644 --- a/lib/rest_framework/utils.rb +++ b/lib/rest_framework/utils.rb @@ -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] } @@ -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? )