Browse Source

fix: decodeURI searching string (#61)

pull/62/head
sigoden 3 years ago committed by GitHub
parent
commit
069cb64889
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      src/server.rs
  2. 12
      tests/http.rs

3
src/server.rs

@ -153,7 +153,8 @@ impl Server {
} else if query == "zip" { } else if query == "zip" {
self.handle_zip_dir(path, head_only, &mut res).await?; self.handle_zip_dir(path, head_only, &mut res).await?;
} else if let Some(q) = query.strip_prefix("q=") { } else if let Some(q) = query.strip_prefix("q=") {
self.handle_query_dir(path, q, head_only, &mut res).await?; let q = decode_uri(q).unwrap_or_default();
self.handle_query_dir(path, &q, head_only, &mut res).await?;
} else { } else {
self.handle_ls_dir(path, true, head_only, &mut res).await?; self.handle_ls_dir(path, true, head_only, &mut res).await?;
} }

12
tests/http.rs

@ -74,6 +74,18 @@ fn get_dir_search(server: TestServer) -> Result<(), Error> {
Ok(()) Ok(())
} }
#[rstest]
fn get_dir_search2(server: TestServer) -> Result<(), Error> {
let resp = reqwest::blocking::get(format!("{}?q={}", server.url(), "😀.data"))?;
assert_eq!(resp.status(), 200);
let paths = utils::retrive_index_paths(&resp.text()?);
assert!(!paths.is_empty());
for p in paths {
assert!(p.contains(&"😀.data"));
}
Ok(())
}
#[rstest] #[rstest]
fn head_dir_search(server: TestServer) -> Result<(), Error> { fn head_dir_search(server: TestServer) -> Result<(), Error> {
let resp = fetch!(b"HEAD", format!("{}?q={}", server.url(), "test.html")).send()?; let resp = fetch!(b"HEAD", format!("{}?q={}", server.url(), "test.html")).send()?;

Loading…
Cancel
Save