File tree Expand file tree Collapse file tree 4 files changed +27
-3
lines changed
Expand file tree Collapse file tree 4 files changed +27
-3
lines changed Original file line number Diff line number Diff line change @@ -2,7 +2,8 @@ import { NullProtoObj } from "../_utils.ts";
22import type { MatchedRoute , ParamsIndexMap } from "../types.ts" ;
33
44export function splitPath ( path : string ) : string [ ] {
5- return path . split ( "/" ) . filter ( Boolean ) ;
5+ const [ _ , ...s ] = path . split ( "/" ) ;
6+ return s [ s . length - 1 ] === "" ? s . slice ( 0 , - 1 ) : s ;
67}
78
89export function getMatchParams (
Original file line number Diff line number Diff line change @@ -25,7 +25,7 @@ export function formatTree(
2525) : string | string [ ] {
2626 result . push (
2727 // prettier-ignore
28- `${ prefix } ${ depth === 0 ? "" : "βββ " } ${ node . key ? `/${ node . key } ` : ( depth === 0 ? "<root>" : "<? >" ) } ${ _formatMethods ( node ) } ` ,
28+ `${ prefix } ${ depth === 0 ? "" : "βββ " } ${ node . key ? `/${ node . key } ` : ( depth === 0 ? "<root>" : "<empty >" ) } ${ _formatMethods ( node ) } ` ,
2929 ) ;
3030
3131 const childrenArray = [
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ describe("benchmark", () => {
1414 ` ;
1515 const { bytes, gzipSize } = await getBundleSize ( code ) ;
1616 console . log ( "bundle size" , { bytes, gzipSize } ) ;
17- expect ( bytes ) . toBeLessThanOrEqual ( 2700 ) ; // <2.7kb
17+ expect ( bytes ) . toBeLessThanOrEqual ( 2800 ) ; // <2.8kb
1818 expect ( gzipSize ) . toBeLessThanOrEqual ( 1100 ) ; // <1.1kb
1919 } ) ;
2020} ) ;
Original file line number Diff line number Diff line change @@ -386,6 +386,29 @@ describe("Router lookup", function () {
386386 } ,
387387 ) ;
388388 } ) ;
389+
390+ describe ( "empty segments" , function ( ) {
391+ testRouter (
392+ [ "/test//route" , "/test/:param/route" ] ,
393+ ( router ) =>
394+ expect ( formatTree ( router . root ) ) . toMatchInlineSnapshot ( `
395+ "<root>
396+ βββ /test
397+ β βββ <empty>
398+ β β βββ /route β> [GET] /test//route
399+ β βββ /*
400+ β β βββ /route β> [GET] /test/:param/route"
401+ ` ) ,
402+ {
403+ "/test//route" : {
404+ data : { path : "/test//route" } ,
405+ } ,
406+ "/test/id/route" : {
407+ data : { path : "/test/:param/route" } ,
408+ } ,
409+ } ,
410+ ) ;
411+ } ) ;
389412} ) ;
390413
391414describe ( "Router insert" , ( ) => {
You canβt perform that action at this time.
0 commit comments