diff options
author | cyqsimon <28627918+cyqsimon@users.noreply.github.com> | 2023-09-05 10:13:51 +0000 |
---|---|---|
committer | cyqsimon <28627918+cyqsimon@users.noreply.github.com> | 2023-09-05 10:13:51 +0000 |
commit | e19370505ff8b428c9ba3daeba830c5785d95a0a (patch) | |
tree | 5965a98229614b32ad265c643aad7781fcab697d | |
parent | Fix incorrect usage of app data extractor (diff) | |
download | miniserve-e19370505ff8b428c9ba3daeba830c5785d95a0a.tar.gz miniserve-e19370505ff8b428c9ba3daeba830c5785d95a0a.zip |
Fix clippy complaints
-rw-r--r-- | src/config.rs | 2 | ||||
-rw-r--r-- | tests/readme.rs | 72 |
2 files changed, 37 insertions, 37 deletions
diff --git a/src/config.rs b/src/config.rs index 50b7343..0959e81 100644 --- a/src/config.rs +++ b/src/config.rs @@ -241,7 +241,7 @@ impl MiniserveConfig { v.iter() .map(|p| { sanitize_path(p, false) - .map(|p| p.display().to_string().replace("\\", "/")) + .map(|p| p.display().to_string().replace('\\', "/")) .ok_or(anyhow!("Illegal path {p:?}: upward traversal not allowed")) }) .collect() diff --git a/tests/readme.rs b/tests/readme.rs index 7faea7b..c8138b4 100644 --- a/tests/readme.rs +++ b/tests/readme.rs @@ -8,6 +8,42 @@ use std::fs::{remove_file, File}; use std::io::Write; use std::path::PathBuf; +fn write_readme_contents(path: PathBuf, filename: &str) -> PathBuf { + let readme_path = path.join(filename); + let mut readme_file = File::create(&readme_path).unwrap(); + readme_file + .write_all(format!("Contents of {filename}").as_bytes()) + .expect("Couldn't write readme"); + readme_path +} + +fn assert_readme_contents(parsed_dom: &Document, filename: &str) { + assert!(parsed_dom.find(Attr("id", "readme")).next().is_some()); + assert!(parsed_dom + .find(Attr("id", "readme-filename")) + .next() + .is_some()); + assert!( + parsed_dom + .find(Attr("id", "readme-filename")) + .next() + .unwrap() + .text() + == filename + ); + assert!(parsed_dom + .find(Attr("id", "readme-contents")) + .next() + .is_some()); + assert!(parsed_dom + .find(Attr("id", "readme-contents")) + .next() + .unwrap() + .text() + .trim() + .contains(&format!("Contents of {filename}"))); +} + /// Do not show readme contents by default #[rstest] fn no_readme_contents(server: TestServer) -> Result<(), Error> { @@ -89,39 +125,3 @@ fn show_nested_readme_contents( } Ok(()) } - -fn write_readme_contents(path: PathBuf, filename: &str) -> PathBuf { - let readme_path = path.join(filename); - let mut readme_file = File::create(&readme_path).unwrap(); - readme_file - .write_all(format!("Contents of {filename}").as_bytes()) - .expect("Couldn't write readme"); - readme_path -} - -fn assert_readme_contents(parsed_dom: &Document, filename: &str) { - assert!(parsed_dom.find(Attr("id", "readme")).next().is_some()); - assert!(parsed_dom - .find(Attr("id", "readme-filename")) - .next() - .is_some()); - assert!( - parsed_dom - .find(Attr("id", "readme-filename")) - .next() - .unwrap() - .text() - == filename - ); - assert!(parsed_dom - .find(Attr("id", "readme-contents")) - .next() - .is_some()); - assert!(parsed_dom - .find(Attr("id", "readme-contents")) - .next() - .unwrap() - .text() - .trim() - .contains(&format!("Contents of {filename}"))); -} |