From: Ardis Lu Date: Fri, 6 Dec 2024 05:14:34 +0000 (-0800) Subject: Fix broken shortUrl validation regex X-Git-Url: https://git.ardis.lu/?a=commitdiff_plain;h=99f4b28507afe41413f9b87361ebb04747d5a23b;p=alu.bz Fix broken shortUrl validation regex Hyphen needs to be escaped to "\-", and alphanumeric can be simplified to "\w". --- 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 @@ - +