Skip to content

Commit 99db1b7

Browse files
committed
fixup!: replace match/split logic
1 parent 2443ed7 commit 99db1b7

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

test/unit/node/update.test.ts

+4-6
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,17 @@ describe("update", () => {
4747

4848
// Checks if url matches /redirect/${number}
4949
// with optional trailing slash
50-
let redirectSlashNumberRegExp = new RegExp(/\/redirect\/([0-9]+)(\/)?$/)
51-
52-
if (request.url.match(redirectSlashNumberRegExp)) {
50+
const match = request.url.match(/\/redirect\/([0-9]+)\/?$/)
51+
if (match) {
5352
if (request.url === "/redirect/0") {
5453
response.writeHead(200)
5554
return response.end("done")
5655
}
5756

5857
// Subtract 1 from the current redirect number
5958
// i.e. /redirect/10 -> /redirect/9 -> /redirect/8
60-
const urlSplit = request.url.split("/")
61-
const currentRedirectNumber = urlSplit[urlSplit.length - 1]
62-
const newRedirectNumber = parseInt(currentRedirectNumber) - 1
59+
const currentRedirectNumber = parseInt(match[1])
60+
const newRedirectNumber = currentRedirectNumber - 1
6361

6462
response.writeHead(302, "testing", {
6563
location: `/redirect/${String(newRedirectNumber)}`,

0 commit comments

Comments
 (0)