Skip to content

Commit

Permalink
Do not add trailing slash
Browse files Browse the repository at this point in the history
  • Loading branch information
augustuswm committed Feb 4, 2019
1 parent 9f01600 commit 6b1ee78
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 6 additions & 17 deletions src/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ParamBag, Box<dyn Error>>;
Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit 6b1ee78

Please sign in to comment.