@@ -584,8 +584,9 @@ pub(crate) async fn get_all_releases(
584
584
Path ( params) : Path < RustdocHtmlParams > ,
585
585
mut conn : DbConnection ,
586
586
) -> 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).
589
590
590
591
let matched_release = match_version ( & mut conn, & params. name , & params. version )
591
592
. await ?
@@ -599,37 +600,8 @@ pub(crate) async fn get_all_releases(
599
600
return Err ( AxumNope :: CrateNotFound ) ;
600
601
}
601
602
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 ( '/' ) ;
633
605
634
606
let target_name = matched_release
635
607
. target_name ( )
@@ -641,19 +613,23 @@ pub(crate) async fn get_all_releases(
641
613
format ! ( "{target_name}/{inner_path}" )
642
614
} ;
643
615
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 ( ) ,
648
624
} ;
649
625
650
- let res = ReleaseList {
626
+ Ok ( ReleaseList {
651
627
releases : matched_release. all_releases ,
652
628
target,
653
629
inner_path,
654
630
crate_name : params. name ,
655
- } ;
656
- Ok ( res . into_response ( ) )
631
+ }
632
+ . into_response ( ) )
657
633
}
658
634
659
635
#[ derive( Debug , Clone , PartialEq ) ]
0 commit comments