diff options
Diffstat (limited to 'web/atward/src')
-rw-r--r-- | web/atward/src/main.rs | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/web/atward/src/main.rs b/web/atward/src/main.rs index 38d0e6939d4e..94e9fff9bc71 100644 --- a/web/atward/src/main.rs +++ b/web/atward/src/main.rs @@ -113,12 +113,18 @@ fn handlers() -> Vec<Handler> { // Depot paths (e.g. //web/atward or //ops/nixos/whitby/default.nix) // TODO(tazjin): Add support for specifying lines in a query parameter Handler { - pattern: Regex::new("^//(?P<path>[a-zA-Z].*)$").unwrap(), + pattern: Regex::new("^//(?P<path>[a-zA-Z].*)?$").unwrap(), target: |query, captures| { + // Pass an empty string if the path is missing, to + // redirect to the depot root. + let path = captures.name("path") + .map(|m| m.as_str()) + .unwrap_or(""); + if query.cs { - Some(sourcegraph_path_url(&captures["path"])) + Some(sourcegraph_path_url(path)) } else { - Some(cgit_url(&captures["path"])) + Some(cgit_url(path)) } }, }, @@ -256,6 +262,20 @@ mod tests { } #[test] + fn depot_root_cgit_query() { + assert_eq!( + dispatch( + &handlers(), + &Query { + query: "//".to_string(), + cs: false, + } + ), + Some("https://code.tvl.fyi/tree/".to_string()), + ); + } + + #[test] fn plain_host_queries() { assert_eq!( dispatch(&handlers(), &"cs".into()), |