From 94eb26fa5935e59bc92b8dfa1256640a7be66ca0 Mon Sep 17 00:00:00 2001 From: alyssadev Date: Sun, 17 Sep 2023 05:34:04 +1000 Subject: [PATCH] fixed bug with case sensitivity --- README.md | 2 +- src/index.js | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index beb9ec4..34be992 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,6 @@ EOF linkie/path => http://example.comhttp//example.com?2 ``` -`curl -n -d u=http://example.com linkie/_`, if you provide an underscore as the path linkie will generate a four character path from a-zA-Z. if it has a collision five times in a row it'll return 500.. at that point i'd probably increase the length of the random ids in the function at the top of index.js to 5 or something, and also i should get off the internet because i've generated 52^4 short urls with this service and that's insane +`curl -n -d u=http://example.com linkie/_`, if you provide an underscore as the path linkie will generate a four character path from a-z0-9. if it has a collision five times in a row it'll return 500.. at that point i'd probably increase the length of the random ids in the function at the top of index.js to 5 or something, and also i should get off the internet because i've generated 36^4 short urls with this service and that's insane See test.py for more usage and test cases diff --git a/src/index.js b/src/index.js index 847bdd1..d1f521b 100644 --- a/src/index.js +++ b/src/index.js @@ -2,7 +2,7 @@ function makeid(length) { let result = ''; - const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; + const characters = 'abcdefghijklmnopqrstuvwxyz0123456789'; const charactersLength = characters.length; let counter = 0; while (counter < length) { @@ -45,12 +45,14 @@ async function add(host,path,request) { x += 1 } } + path = path.toLowerCase() await KV.put(path, dest) return new Response(`https://${host}/${path}`, {status:201}) } async function remove(host,path) { if (!path) return new Response("No path provided",{status:400}) + path = path.toLowerCase() await KV.delete(path) return new Response(`DELETE https://${host}/${path}`, {status:200}) } @@ -63,6 +65,7 @@ async function get(host,path,auth) { return new Response(paths,{status:200}) } if (!path) return Response.redirect("https://aly-smith.carrd.co",301) + path = path.toLowerCase() const dest = await KV.get(path) if (dest) return Response.redirect(dest, 302) return new Response("Path not found", {status:404})