Skip to content

Commit

Permalink
fix: Replace multiple occurrences of token in fallback URL
Browse files Browse the repository at this point in the history
  • Loading branch information
shrink committed Dec 13, 2024
1 parent 53eaba4 commit f836436
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@handles-net/handles-server",
"version": "0.3.0",
"version": "0.3.1",
"description": "Verify Bluesky handles.",
"keywords": [
"bluesky",
Expand Down
18 changes: 18 additions & 0 deletions server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,22 @@ describe("Handles Server", () => {
"https://example.com/domains/at.example.com?handle=not-registered.at.example.com",
);
});

test("Replaces multiple instances of token in fallback URL", async () => {
const res = await performRequest(
{
method: "GET",
url: "/",
headers: { Host: "not-registered.at.example.com" },
},
{
fallbackUrl: "https://example.com/{handle}?handle={handle}",
},
);

expect(res._getStatusCode()).toBe(307);
expect(res._getHeaders().location).toBe(
"https://example.com/not-registered.at.example.com?handle=not-registered.at.example.com",
);
})
});
2 changes: 1 addition & 1 deletion server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export async function handleRequest(

Object.entries({ domain, handle }).forEach(
([token, value]) =>
(noProfileDestination = noProfileDestination.replace(
(noProfileDestination = noProfileDestination.replaceAll(
`{${token}}`,
value,
)),
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"compilerOptions": {
"baseUrl": ".",
"target": "es2016",
"target": "es2021",
"module": "commonjs",
"outDir": "./dist",
"esModuleInterop": true,
Expand Down

0 comments on commit f836436

Please sign in to comment.