From f98c9ae8f8129a81908967566945f702a0738b59 Mon Sep 17 00:00:00 2001 From: panteliselef Date: Wed, 7 Feb 2024 12:57:11 +0200 Subject: [PATCH] fix(backend): Preserve url protocol when joining paths --- .changeset/yellow-walls-worry.md | 5 +++++ packages/backend/src/util/__tests__/path.test.ts | 14 ++++++++++++++ packages/backend/src/util/path.ts | 2 +- 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 .changeset/yellow-walls-worry.md diff --git a/.changeset/yellow-walls-worry.md b/.changeset/yellow-walls-worry.md new file mode 100644 index 00000000000..db0de86d7f9 --- /dev/null +++ b/.changeset/yellow-walls-worry.md @@ -0,0 +1,5 @@ +--- +'@clerk/backend': patch +--- + +Preserve url protocol when joining paths. diff --git a/packages/backend/src/util/__tests__/path.test.ts b/packages/backend/src/util/__tests__/path.test.ts index ce632d73a82..3ebeb9160c7 100644 --- a/packages/backend/src/util/__tests__/path.test.ts +++ b/packages/backend/src/util/__tests__/path.test.ts @@ -10,4 +10,18 @@ export default (QUnit: QUnit) => { test('joins the provides paths safely', assert => { assert.equal(joinPaths('foo', '/bar', '/qux//'), 'foo/bar/qux/'); }); + + test('does not affect url scheme', assert => { + assert.equal( + joinPaths('https://api.clerk.com', 'v1', '/organizations/org_xxxxxxxxxxxxxxxxx'), + 'https://api.clerk.com/v1/organizations/org_xxxxxxxxxxxxxxxxx', + ); + }); + + test('does not affect url scheme and removes duplicate separators', assert => { + assert.equal( + joinPaths('https://api.clerk.com//', '/v1/', '//organizations/org_xxxxxxxxxxxxxxxxx//'), + 'https://api.clerk.com/v1/organizations/org_xxxxxxxxxxxxxxxxx/', + ); + }); }; diff --git a/packages/backend/src/util/path.ts b/packages/backend/src/util/path.ts index 708288bc14c..3e191aa6436 100644 --- a/packages/backend/src/util/path.ts +++ b/packages/backend/src/util/path.ts @@ -1,5 +1,5 @@ const SEPARATOR = '/'; -const MULTIPLE_SEPARATOR_REGEX = new RegExp(SEPARATOR + '{1,}', 'g'); +const MULTIPLE_SEPARATOR_REGEX = new RegExp('(?