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('(?