@@ -381,7 +381,7 @@ fn fix_redirects_internal(
381
381
// Split the clean pairs into their respective locales
382
382
let locale_pairs = clean_pairs. into_iter ( ) . try_fold (
383
383
HashMap :: < Locale , HashMap < String , String > > :: new ( ) ,
384
- |mut acc, ( from, to) | -> Result < HashMap < Locale , HashMap < String , String > > , ToolError > {
384
+ |mut acc, ( from, mut to) | -> Result < HashMap < Locale , HashMap < String , String > > , ToolError > {
385
385
// Extract the locale string from the 'from' path
386
386
let locale_str = from. split ( '/' ) . nth ( 1 ) . unwrap_or_default ( ) ;
387
387
@@ -392,6 +392,14 @@ fn fix_redirects_internal(
392
392
from, from, to
393
393
) ) )
394
394
} ) ?;
395
+ if to. starts_with ( '/' ) {
396
+ let ( bare_url, hash) = to. split_once ( '#' ) . map ( |( u, h) | ( u, Some ( h) ) ) . unwrap_or ( ( & to, None ) ) ;
397
+ if let Ok ( page) = Page :: from_url ( bare_url) {
398
+ if page. url ( ) != bare_url {
399
+ to = if let Some ( hash) = hash { concat_strs ! ( page. url( ) , "#" , hash) } else { page. url ( ) . to_string ( ) } ;
400
+ }
401
+ }
402
+ }
395
403
let locale_map = acc. entry ( locale) . or_default ( ) ;
396
404
locale_map. insert ( from, to) ;
397
405
Ok ( acc)
@@ -654,6 +662,17 @@ fn validate_to_url(url: &str, locale: Locale) -> Result<(), ToolError> {
654
662
locale
655
663
) ) ) ;
656
664
}
665
+ if let Ok ( page) = Page :: from_url ( bare_url) {
666
+ if page. url ( ) != bare_url {
667
+ return Err ( ToolError :: InvalidRedirectToURL ( format ! (
668
+ "To-URL '{}' does not equal page url '{}' for '{}' for locale '{}'." ,
669
+ bare_url,
670
+ page. url( ) ,
671
+ path. display( ) ,
672
+ locale
673
+ ) ) ) ;
674
+ }
675
+ }
657
676
} else {
658
677
return Err ( ToolError :: InvalidRedirectToURL ( format ! (
659
678
"To-URL '{}' has to be external (https://) or start with '/' for locale '{}'." ,
0 commit comments