From aebd192f2551c12c5c88f9371ad2912382d04b6a Mon Sep 17 00:00:00 2001 From: Akbar Rahman Date: Sat, 9 May 2026 23:00:15 +0100 Subject: [PATCH] make shortlinks case insensitive --- readme.md | 23 ++++++++++++++++++++++- src/main.rs | 5 +++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/readme.md b/readme.md index ef15034..a4c7b0a 100644 --- a/readme.md +++ b/readme.md @@ -33,6 +33,27 @@ a _really_ simple url shortener: less than 200 lines of Rust and one dependency a working [dockerfile](./Dockerfile) and [compose file](./compose.yaml) are provided. +## a note on case insensitivity + +all shortlinks are case insenitive, +due to the lack of [urlencoding/decoding](#a-note-on-urlencoded-characters). + +## a note on urlencoded characters + +this program does not decode urlencoded strings before checking if strings match. +this is a deliberate choice to keep things as simple as possible. + +avoid using links that may be encoded. + +for links that will necessarily get encoded (still discouraged) (such as emojis), +put the urlencoded string. +for example, for the link the following line is in my urls.txt: + +``` +/🤬 https://en.wikipedia.org/wiki/Controversies_of_Nestl%C3%A9 you may want the non-encoded version in case a client does not encode it? idk +/%f0%9f%a4%ac https://en.wikipedia.org/wiki/Controversies_of_Nestl%C3%A9 +``` + ## why? all url shorteners i've come across are too complicated: @@ -47,7 +68,7 @@ updating it. good question. i'm not sure, but i think i want to separate my concerns? -you might just want to configure your reverse proxy instead. +you might just want to configure your reverse proxy instead: #### caddy diff --git a/src/main.rs b/src/main.rs index 8d3c91f..b9e88e8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -46,6 +46,7 @@ async fn process_socket(mut socket: BufStream, urlmap: Arc, urlmap: Arc Result<(), Box> { Err(format!("Unable to parse line: '{}'", url_pair))? }; - urlmap.insert(slug.to_string(), redirect.to_string()); + urlmap.insert(slug.to_lowercase(), redirect.to_string()); } let urlmap = Arc::new(urlmap);