From 99f4b28507afe41413f9b87361ebb04747d5a23b Mon Sep 17 00:00:00 2001 From: Ardis Lu Date: Thu, 5 Dec 2024 21:14:34 -0800 Subject: [PATCH] Fix broken shortUrl validation regex Hyphen needs to be escaped to "\-", and alphanumeric can be simplified to "\w". --- functions/api.js | 2 +- index.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/functions/api.js b/functions/api.js index 4e90769..6ff41f8 100644 --- a/functions/api.js +++ b/functions/api.js @@ -51,7 +51,7 @@ export async function onRequestPost({ request, env }) { } while (await env.links.get(shortUrl) !== null); // Confirm it's not already taken } // Invalid short URLs - else if (!/^[0-9a-zA-Z-_]*$/g.test(shortUrl) || shortUrl === 'api') { + else if (!/^[\w\-]+$/g.test(shortUrl) || shortUrl === 'api') { return new Response('Invalid short URL.', { status: 400, headers: { 'Content-Type': 'text/plain; charset=UTF-8' } }); } // User-provided duplicates diff --git a/index.html b/index.html index 10c1cb6..42695ca 100644 --- a/index.html +++ b/index.html @@ -52,7 +52,7 @@ - + -- 2.47.3