From 7dc0eba48af04c4f325bee7c1ce6df41d76d68b7 Mon Sep 17 00:00:00 2001 From: Pranav Date: Tue, 12 Nov 2024 10:38:29 -0800 Subject: [PATCH] fix: Remove duplicate `/` character on the proxy route (#10404) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The proxy method adds an extra slash even if the route param has the character. It’s challenging to check the expected format on each route. The simplest solution is to check if the route param begins with a slash, and if not, append one. NB: The existing tests are sufficient to cover this case. There’s no need for an additional test to specifically test this. --- .../accounts/integrations/captain_controller.rb | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/app/controllers/api/v1/accounts/integrations/captain_controller.rb b/app/controllers/api/v1/accounts/integrations/captain_controller.rb index 840fe5428..15e81b726 100644 --- a/app/controllers/api/v1/accounts/integrations/captain_controller.rb +++ b/app/controllers/api/v1/accounts/integrations/captain_controller.rb @@ -18,11 +18,11 @@ class Api::V1::Accounts::Integrations::CaptainController < Api::V1::Accounts::Ba end def request_path - if params[:route] == '/sessions/profile' - 'api/sessions/profile' - else - "api/accounts/#{hook.settings['account_id']}/#{params[:route]}" - end + request_route = with_leading_hash_on_route(params[:route]) + + return 'api/sessions/profile' if request_route == '/sessions/profile' + + "api/accounts/#{hook.settings['account_id']}#{request_route}" end def request_url @@ -41,6 +41,12 @@ class Api::V1::Accounts::Integrations::CaptainController < Api::V1::Accounts::Ba method end + def with_leading_hash_on_route(request_route) + return '' if request_route.blank? + + request_route.start_with?('/') ? request_route : "/#{request_route}" + end + def permitted_params params.permit(:method, :route, body: {}) end