From 2dd5ae400cf0d838e50fb9a39e71ac50eb2f6173 Mon Sep 17 00:00:00 2001 From: Sam Briggs <89932826+sam-briggs-depop@users.noreply.github.com> Date: Thu, 26 Sep 2024 06:48:18 +0100 Subject: [PATCH] Fix #2760: Path params trailing slash (#3065) As reported in #2670, if a URL has a trailing slash and also contains path parameters then the original logic had a bug that would drop the trailing slash. This implements the fix proposed by @ThenTech. --- packages/bruno-cli/src/runner/interpolate-vars.js | 3 ++- packages/bruno-electron/src/ipc/network/interpolate-vars.js | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/bruno-cli/src/runner/interpolate-vars.js b/packages/bruno-cli/src/runner/interpolate-vars.js index 39e92a6ec..0253c10cd 100644 --- a/packages/bruno-cli/src/runner/interpolate-vars.js +++ b/packages/bruno-cli/src/runner/interpolate-vars.js @@ -122,7 +122,8 @@ const interpolateVars = (request, envVars = {}, runtimeVariables = {}, processEn }) .join(''); - request.url = url.origin + interpolatedUrlPath + url.search; + const trailingSlash = url.pathname.endsWith('/') ? '/' : ''; + request.url = url.origin + interpolatedUrlPath + trailingSlash + url.search; } if (request.proxy) { diff --git a/packages/bruno-electron/src/ipc/network/interpolate-vars.js b/packages/bruno-electron/src/ipc/network/interpolate-vars.js index 90b072658..5ea2bf7f4 100644 --- a/packages/bruno-electron/src/ipc/network/interpolate-vars.js +++ b/packages/bruno-electron/src/ipc/network/interpolate-vars.js @@ -120,7 +120,8 @@ const interpolateVars = (request, envVariables = {}, runtimeVariables = {}, proc }) .join(''); - request.url = url.origin + urlPathnameInterpolatedWithPathParams + url.search; + const trailingSlash = url.pathname.endsWith('/') ? '/' : ''; + request.url = url.origin + urlPathnameInterpolatedWithPathParams + trailingSlash + url.search; } if (request.proxy) {