Skip to content

Commit

Permalink
fix(backend): Preserve url protocol when joining paths (#2745)
Browse files Browse the repository at this point in the history
  • Loading branch information
panteliselef authored Feb 7, 2024
1 parent e883533 commit c2b9827
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/yellow-walls-worry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@clerk/backend': patch
---

Preserve url protocol when joining paths.
14 changes: 14 additions & 0 deletions packages/backend/src/util/__tests__/path.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/',
);
});
};
2 changes: 1 addition & 1 deletion packages/backend/src/util/path.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const SEPARATOR = '/';
const MULTIPLE_SEPARATOR_REGEX = new RegExp(SEPARATOR + '{1,}', 'g');
const MULTIPLE_SEPARATOR_REGEX = new RegExp('(?<!:)' + SEPARATOR + '{1,}', 'g');

type PathString = string | null | undefined;

Expand Down

0 comments on commit c2b9827

Please sign in to comment.