From e9ea53eb45c9b9b4b3ea9eb815dc89c8711dd272 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Mon, 22 Apr 2024 15:22:23 -0400 Subject: [PATCH] Remove trailing / --- crates/utils/src/utils/validation.rs | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/crates/utils/src/utils/validation.rs b/crates/utils/src/utils/validation.rs index 96b12c06b..a6539f1b1 100644 --- a/crates/utils/src/utils/validation.rs +++ b/crates/utils/src/utils/validation.rs @@ -335,13 +335,18 @@ pub fn build_url_str_without_scheme(url_str: &str) -> LemmyResult { .set_scheme("http") .map_err(|_| LemmyErrorType::InvalidUrl)?; - Ok( - url - .to_string() - .get(7..) - .ok_or(LemmyErrorType::InvalidUrl)? - .to_string(), - ) + let mut out = url + .to_string() + .get(7..) + .ok_or(LemmyErrorType::InvalidUrl)? + .to_string(); + + // Remove trailing / if necessary + if out.ends_with('/') { + out.pop(); + } + + Ok(out) } #[cfg(test)] @@ -628,7 +633,7 @@ mod tests { ]) .unwrap(), &vec![ - "example.com/".to_string(), + "example.com".to_string(), "example.com/test?q=test2&q2=test3#test4".to_string() ], );