@@ -584,8 +584,9 @@ pub(crate) async fn get_all_releases(
584584 Path ( params) : Path < RustdocHtmlParams > ,
585585 mut conn : DbConnection ,
586586) -> AxumResult < AxumResponse > {
587- let req_path: String = params. path . clone ( ) . unwrap_or_default ( ) ;
588- let req_path: Vec < & str > = req_path. split ( '/' ) . collect ( ) ;
587+ // NOTE: we're getting RustDocHtmlParams here, where both target and path are optional.
588+ // Due to how this handler is used in the `releases_list` macro, we either have
589+ // both values (when used in the topbar), or none (when used in the crate-details handler).
589590
590591 let matched_release = match_version ( & mut conn, & params. name , & params. version )
591592 . await ?
@@ -599,37 +600,8 @@ pub(crate) async fn get_all_releases(
599600 return Err ( AxumNope :: CrateNotFound ) ;
600601 }
601602
602- let doc_targets = sqlx:: query_scalar!(
603- "SELECT
604- releases.doc_targets
605- FROM releases
606- WHERE releases.id = $1;" ,
607- matched_release. id( ) . 0 ,
608- )
609- . fetch_optional ( & mut * conn)
610- . await ?
611- . ok_or ( AxumNope :: CrateNotFound ) ?
612- . map ( MetaData :: parse_doc_targets)
613- . ok_or_else ( || anyhow ! ( "empty doc targets for successful release" ) ) ?;
614-
615- let inner;
616- let ( target, inner_path) = {
617- let mut inner_path = req_path. clone ( ) ;
618-
619- let target = if inner_path. len ( ) > 1
620- && doc_targets
621- . iter ( )
622- . any ( |s| Some ( s) == params. target . as_ref ( ) )
623- {
624- inner_path. remove ( 0 ) ;
625- params. target . as_ref ( ) . unwrap ( )
626- } else {
627- ""
628- } ;
629-
630- inner = inner_path. join ( "/" ) ;
631- ( target, inner. trim_end_matches ( '/' ) )
632- } ;
603+ let inner_path = params. path . unwrap_or_default ( ) ;
604+ let inner_path = inner_path. trim_end_matches ( '/' ) ;
633605
634606 let target_name = matched_release
635607 . target_name ( )
@@ -641,19 +613,23 @@ pub(crate) async fn get_all_releases(
641613 format ! ( "{target_name}/{inner_path}" )
642614 } ;
643615
644- let target = if target. is_empty ( ) {
645- String :: new ( )
646- } else {
647- format ! ( "{target}/" )
616+ // NOTE: we don't check if the target exists here.
617+ // If the target doesn't exist, the target-redirect will think
618+ // it's part of the `inner_path`, don't find the file in storage,
619+ // and redirect to a search.
620+ let target = match params. target {
621+ Some ( t) if t. is_empty ( ) => t,
622+ Some ( t) => format ! ( "{t}/" ) ,
623+ None => String :: new ( ) ,
648624 } ;
649625
650- let res = ReleaseList {
626+ Ok ( ReleaseList {
651627 releases : matched_release. all_releases ,
652628 target,
653629 inner_path,
654630 crate_name : params. name ,
655- } ;
656- Ok ( res . into_response ( ) )
631+ }
632+ . into_response ( ) )
657633}
658634
659635#[ derive( Debug , Clone , PartialEq ) ]
0 commit comments