From 6b1ee781ff56fc3a75955e15dcbdae2ad916ba87 Mon Sep 17 00:00:00 2001 From: Augustus Mayo Date: Mon, 4 Feb 2019 10:27:18 -0600 Subject: [PATCH] Do not add trailing slash --- Cargo.lock | 2 +- src/params.rs | 23 ++++++----------------- 2 files changed, 7 insertions(+), 18 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d3cd901..7713438 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -283,7 +283,7 @@ dependencies = [ [[package]] name = "envfmt" -version = "0.1.0" +version = "0.2.0" dependencies = [ "rusoto_core 0.36.0 (registry+https://github.com/rust-lang/crates.io-index)", "rusoto_mock 0.30.0 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/src/params.rs b/src/params.rs index f757beb..479c9ef 100644 --- a/src/params.rs +++ b/src/params.rs @@ -32,17 +32,10 @@ impl ParamBag { } pub fn normalize_path(path: &str) -> String { - let with_leading_slash = match path.chars().next() { + match path.chars().next() { Some('/') => path.to_string(), _ => "/".to_string() + path, - }; - - let normalized = match with_leading_slash.chars().last() { - Some('/') => with_leading_slash, - _ => with_leading_slash + "/", - }; - - normalized + } } type ParamResult = Result>; @@ -194,14 +187,10 @@ mod tests { #[test] fn test_normalizes_path_on_construction() { let b1 = ParamBag::new("/path/to/the"); - let b2 = ParamBag::new("/path/to/the/"); - let b3 = ParamBag::new("/path/to/the"); - let b4 = ParamBag::new("path/to/the/"); - - assert_eq!("/path/to/the/", b1.prefix); - assert_eq!("/path/to/the/", b2.prefix); - assert_eq!("/path/to/the/", b3.prefix); - assert_eq!("/path/to/the/", b4.prefix); + let b2 = ParamBag::new("path/to/the"); + + assert_eq!("/path/to/the", b1.prefix); + assert_eq!("/path/to/the", b2.prefix); } #[test]