From f2366f4f95b0011aab517264e0ae84419abef660 Mon Sep 17 00:00:00 2001 From: iximeow Date: Sat, 1 Jul 2023 23:47:23 -0700 Subject: produce short sha after looking up the full sha so short urls do not panic from invalid bounds --- src/main.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index 1325d16..6f49cc8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -481,7 +481,6 @@ async fn handle_commit_status(Path(path): Path<(String, String, String)>, State( eprintln!("path: {}/{}, sha {}", path.0, path.1, path.2); let remote_path = format!("{}/{}", path.0, path.1); let sha = path.2; - let short_sha = &sha[0..9]; let (commit_id, sha): (u64, String) = if sha.len() >= 7 { match ctx.dbctx.conn.lock().unwrap() @@ -497,6 +496,8 @@ async fn handle_commit_status(Path(path): Path<(String, String, String)>, State( return (StatusCode::NOT_FOUND, Html("no such commit".to_string())); }; + let short_sha = &sha[0..9]; + let (remote_id, repo_id): (u64, u64) = ctx.dbctx.conn.lock().unwrap() .query_row("select id, repo_id from remotes where remote_path=?1;", [&remote_path], |row| Ok((row.get_unwrap(0), row.get_unwrap(1)))) .expect("can query"); -- cgit v1.1