File tree Expand file tree Collapse file tree 3 files changed +20
-4
lines changed Expand file tree Collapse file tree 3 files changed +20
-4
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ ' @sveltejs/kit ' : patch
3+ ---
4+
5+ Fix pattern matching for routes starting with an encoded ` @ ` symbol
Original file line number Diff line number Diff line change @@ -16,11 +16,12 @@ export function parse_route_id(id) {
1616 id === ''
1717 ? / ^ \/ $ /
1818 : new RegExp (
19- `^${ decodeURIComponent ( id )
19+ `^${ id
2020 . split ( / (?: @ [ a - z A - Z 0 - 9 _ - ] + ) ? (?: \/ | $ ) / )
2121 . map ( ( segment , i , segments ) => {
22+ const decoded_segment = decodeURIComponent ( segment ) ;
2223 // special case — /[...rest]/ could contain zero segments
23- const match = / ^ \[ \. \. \. ( \w + ) (?: = ( \w + ) ) ? \] $ / . exec ( segment ) ;
24+ const match = / ^ \[ \. \. \. ( \w + ) (?: = ( \w + ) ) ? \] $ / . exec ( decoded_segment ) ;
2425 if ( match ) {
2526 names . push ( match [ 1 ] ) ;
2627 types . push ( match [ 2 ] ) ;
@@ -30,9 +31,9 @@ export function parse_route_id(id) {
3031 const is_last = i === segments . length - 1 ;
3132
3233 return (
33- segment &&
34+ decoded_segment &&
3435 '/' +
35- segment
36+ decoded_segment
3637 . split ( / \[ ( .+ ?) \] / )
3738 . map ( ( content , i ) => {
3839 if ( i % 2 ) {
Original file line number Diff line number Diff line change @@ -42,6 +42,16 @@ const tests = {
4242 pattern : / ^ \/ m a t c h e d \/ ( [ ^ / ] + ?) \/ ? $ / ,
4343 names : [ 'id' ] ,
4444 types : [ 'uuid' ]
45+ } ,
46+ '%23hash-encoded' : {
47+ pattern : / ^ \/ % 2 3 h a s h - e n c o d e d \/ ? $ / ,
48+ names : [ ] ,
49+ types : [ ]
50+ } ,
51+ '%40at-encoded/[id]' : {
52+ pattern : / ^ \/ @ a t - e n c o d e d \/ ( [ ^ / ] + ?) \/ ? $ / ,
53+ names : [ 'id' ] ,
54+ types : [ undefined ]
4555 }
4656} ;
4757
You can’t perform that action at this time.
0 commit comments