File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -72,6 +72,8 @@ function compilePath(path) {
7272/**
7373 * Last static segment of a dynamic route pattern. Positions skip empty
7474 * segments so they line up with a leading-slash pathname split.
75+ * Returns null when a catch-all precedes that token: `*` can span slashes,
76+ * so the token's pathname index is not fixed and the route is scanned.
7577 *
7678 * @param {string } path
7779 * @returns {{ pos: number, value: string } | null }
@@ -81,17 +83,22 @@ function lastStaticSegment(path) {
8183 let pos = - 1 ;
8284 let value = '' ;
8385 let index = 0 ;
86+ let sawCatchAll = false ;
87+ let catchAllBefore = false ;
8488 for ( let i = 0 ; i < raw . length ; i ++ ) {
8589 const segment = raw [ i ] ;
8690 if ( ! segment ) continue ;
8791 const first = segment . charCodeAt ( 0 ) ;
88- if ( first !== 58 /* : */ && first !== 42 /* * */ ) {
92+ if ( first === 42 /* * */ ) {
93+ sawCatchAll = true ;
94+ } else if ( first !== 58 /* : */ ) {
8995 pos = index ;
9096 value = segment ;
97+ catchAllBefore = sawCatchAll ;
9198 }
9299 index ++ ;
93100 }
94- if ( pos === - 1 ) return null ;
101+ if ( pos === - 1 || catchAllBefore ) return null ;
95102 return { pos, value } ;
96103}
97104
Original file line number Diff line number Diff line change @@ -143,4 +143,19 @@ describe('app-core request router', () => {
143143 params : { slug : 'guides/setup/' } ,
144144 } ) ;
145145 } ) ;
146+
147+ it ( 'matches a catch-all that sits before a later static segment' , function ( ) {
148+ const raw = new RenderRoute ( { path : '/files/*path/raw' , entry : '/src/raw.tsrx' } ) ;
149+ const router = createRouter ( [ raw ] ) ;
150+
151+ expect ( router . match ( 'GET' , '/files/a/b/raw' ) ) . toEqual ( {
152+ route : raw ,
153+ params : { path : 'a/b' } ,
154+ } ) ;
155+ expect ( router . match ( 'GET' , '/files/a/raw' ) ) . toEqual ( {
156+ route : raw ,
157+ params : { path : 'a' } ,
158+ } ) ;
159+ expect ( router . match ( 'GET' , '/files/raw' ) ) . toBeNull ( ) ;
160+ } ) ;
146161} ) ;
You can’t perform that action at this time.
0 commit comments