diff options
author | Kornel <kornel@geekhood.net> | 2020-02-25 14:15:12 +0000 |
---|---|---|
committer | Kornel <kornel@geekhood.net> | 2020-02-25 14:19:31 +0000 |
commit | 05916464a25af7b96b4643118e9e44859c8e1292 (patch) | |
tree | 058c23bd1008c845ec93ea7e5b55b2f217130523 | |
parent | 5653d72f49d154340ad3a0ba4ae135b1feaa3870 (diff) |
Url fix
-rw-r--r-- | server/src/main.rs | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/server/src/main.rs b/server/src/main.rs index 8498784..5f58d58 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -352,7 +352,7 @@ async fn handle_git_crate(req: HttpRequest, slug: &'static str) -> Result<HttpRe let repo = inf.query("repo"); let crate_name = inf.query("crate"); println!("{} crate {}/{}/{}", slug, owner, repo, crate_name); - if !is_alnum(&owner) || !is_alnum_dot(&repo) || !is_alnum(&crate_name) { + if !is_alnum_dot(&owner) || !is_alnum_dot(&repo) || !is_alnum(&crate_name) { return render_404_page(state, &crate_name); } @@ -589,15 +589,15 @@ fn serve_cached((page, cache_time, refresh, last_modified): (Vec<u8>, u32, bool, } fn is_alnum(q: &str) -> bool { - q.chars().all(|c| c.is_ascii_alphanumeric() || c == '_' || c == '-') + q.as_bytes().iter().copied().all(|c| c.is_ascii_alphanumeric() || c == b'_' || c == b'-') } fn is_alnum_dot(q: &str) -> bool { - let mut chars = q.chars(); - if !chars.next().map_or(false, |first| first.is_ascii_alphanumeric() || first == '_') { + let mut chars = q.as_bytes().iter().copied(); + if !chars.next().map_or(false, |first| first.is_ascii_alphanumeric() || first == b'_') { return false; } - chars.all(|c| c.is_ascii_alphanumeric() || c == '_' || c == '-' || c == '.') + chars.all(|c| c.is_ascii_alphanumeric() || c == b'_' || c == b'-' || c == b'.') } async fn handle_search(req: HttpRequest) -> Result<HttpResponse, failure::Error> { |