@@ -482,8 +482,8 @@ async function lookupSiteInMultiMode(request: NextRequest, url: URL): Promise<Lo
482
482
*
483
483
* The format of the path is:
484
484
* - /~space|~site/:id/:path
485
- * - /~space|~site/:id/~changes/:changeId/:path
486
- * - /~space|~site/:id/~revisions/:revisionId/:path
485
+ * - /~space|~site/:id/~/ changes/:changeId/:path
486
+ * - /~space|~site/:id/~/ revisions/:revisionId/:path
487
487
*/
488
488
async function lookupSiteOrSpaceInMultiIdMode (
489
489
request : NextRequest ,
@@ -492,13 +492,17 @@ async function lookupSiteOrSpaceInMultiIdMode(
492
492
const basePathParts : string [ ] = [ ] ;
493
493
const pathSegments = url . pathname . slice ( 1 ) . split ( '/' ) ;
494
494
495
- const eatPathId = ( prefix : string ) : string | undefined => {
496
- if ( pathSegments [ 0 ] !== prefix || pathSegments . length < 2 ) {
495
+ const eatPathId = ( ...prefixes : string [ ] ) : string | undefined => {
496
+ const match = prefixes . every ( ( prefix , index ) => pathSegments [ index ] === prefix ) ;
497
+ if ( ! match || pathSegments . length < prefixes . length + 1 ) {
497
498
return ;
498
499
}
499
500
500
- const prefixSegment = pathSegments . shift ( ) ;
501
- basePathParts . push ( prefixSegment ! ) ;
501
+ // Remove the prefix from the path segments
502
+ pathSegments . splice ( 0 , prefixes . length ) ;
503
+
504
+ // Add the prefix to the base path
505
+ basePathParts . push ( ...prefixes ) ;
502
506
503
507
const id = pathSegments . shift ( ) ;
504
508
basePathParts . push ( id ! ) ;
@@ -524,8 +528,8 @@ async function lookupSiteOrSpaceInMultiIdMode(
524
528
}
525
529
526
530
// Extract the change request or revision ID from the path
527
- const changeRequestId = eatPathId ( '~changes' ) ;
528
- const revisionId = eatPathId ( '~revisions' ) ;
531
+ const changeRequestId = eatPathId ( '~' , ' changes') ;
532
+ const revisionId = eatPathId ( '~' , ' revisions') ;
529
533
530
534
// Get the auth token from the URL query
531
535
const AUTH_TOKEN_QUERY = 'token' ;
0 commit comments