From f10c2e0de7fde0051f848609a29c2906d0caa1d9 Mon Sep 17 00:00:00 2001 From: Marc Hassan Date: Tue, 18 Mar 2025 14:01:37 -0400 Subject: [PATCH] fix(buildFullPath): handle `allowAbsoluteUrls: false` without `baseURL` (#6833) Co-authored-by: Jay --- lib/core/buildFullPath.js | 2 +- test/specs/core/buildFullPath.spec.js | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/core/buildFullPath.js b/lib/core/buildFullPath.js index ba07b22..3050bd6 100644 --- a/lib/core/buildFullPath.js +++ b/lib/core/buildFullPath.js @@ -15,7 +15,7 @@ import combineURLs from '../helpers/combineURLs.js'; */ export default function buildFullPath(baseURL, requestedURL, allowAbsoluteUrls) { let isRelativeUrl = !isAbsoluteURL(requestedURL); - if (baseURL && isRelativeUrl || allowAbsoluteUrls == false) { + if (baseURL && (isRelativeUrl || allowAbsoluteUrls == false)) { return combineURLs(baseURL, requestedURL); } return requestedURL; diff --git a/test/specs/core/buildFullPath.spec.js b/test/specs/core/buildFullPath.spec.js index 2dfbe1b..19319cb 100644 --- a/test/specs/core/buildFullPath.spec.js +++ b/test/specs/core/buildFullPath.spec.js @@ -13,6 +13,10 @@ describe('helpers::buildFullPath', function () { expect(buildFullPath('https://api.github.com', 'https://api.example.com/users', false)).toBe('https://api.github.com/https://api.example.com/users'); }); + it('should not combine the URLs when the requestedURL is absolute, allowAbsoluteUrls is false, and the baseURL is not configured', function () { + expect(buildFullPath(undefined, 'https://api.example.com/users', false)).toBe('https://api.example.com/users'); + }); + it('should not combine URLs when the baseURL is not configured', function () { expect(buildFullPath(undefined, '/users')).toBe('/users'); });