From 303389de14566d68147683d48e1f6cfad30aeedc Mon Sep 17 00:00:00 2001 From: Emi Simpson Date: Fri, 15 Jul 2022 14:29:23 -0400 Subject: [PATCH] Remove the requirement on ordering for domains --- README.md | 2 -- src/server.rs | 9 +++++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 351d851..6056c2a 100644 --- a/README.md +++ b/README.md @@ -49,8 +49,6 @@ queerings.gay getonflop.xyz ``` -One restriction: If one site is a substring of another, the shorter site must go first. For example, if you have `unix.pub` and `unix.pub/~user`, `unix.pub` MUST be higher in the list than `unix.pub/~user` - Now, run the Faery Ring binary (or docker image) with the `.txt` file you just created as the first argument, like this: ```bash diff --git a/src/server.rs b/src/server.rs index f255068..0f9bd8f 100644 --- a/src/server.rs +++ b/src/server.rs @@ -67,9 +67,14 @@ impl<'a> Route<'a> { match self { Self::PrevOrNext(this_domain, offset) => { + // The name of the domain at the index of the index of shortest matching + // domain from the list for which the requested domain is a substring, + // offset by the offset. let destination = domains.iter() - .position(|d| d.as_str().starts_with(this_domain)) - .map(|i| (i as isize + offset).rem_euclid(domains.len() as isize)) + .enumerate() + .filter(|(_, d)| d.as_str().starts_with(this_domain)) + .min_by_key(|(_, d)| d.len()) + .map(|(i, _)| (i as isize + offset).rem_euclid(domains.len() as isize)) .map(|i| domains[i as usize]); // safe to unwrap: we just did a rem_euclid if let Some(url) = destination {