@@ -987,4 +987,64 @@ describe('Tree', () => {
987987 } ) // query param
988988 } )
989989 } )
990+
991+ describe ( 'Empty parameter names' , ( ) => {
992+ it ( 'assigns default name "pathMatch" to empty parameter names' , ( ) => {
993+ const tree = new PrefixTree ( RESOLVED_OPTIONS )
994+ let node = tree . insertParsedPath ( '/:()bar' , 'test.vue' )
995+
996+ expect (
997+ 'Invalid parameter in path "/:()bar": parameter name cannot be empty'
998+ ) . toHaveBeenWarned ( )
999+ // The empty param gets assigned the default name "pathMatch"
1000+ expect ( node . value . isParam ( ) ) . toBe ( true )
1001+ if ( node . value . isParam ( ) ) {
1002+ expect ( node . value . pathParams ) . toHaveLength ( 1 )
1003+ expect ( node . value . pathParams [ 0 ] ) . toMatchObject ( {
1004+ paramName : 'pathMatch' ,
1005+ } )
1006+ }
1007+
1008+ // Empty param at the start - gets default name
1009+ node = tree . insertParsedPath ( '/:()' , 'test1.vue' )
1010+ expect (
1011+ 'Invalid parameter in path "/:()": parameter name cannot be empty'
1012+ ) . toHaveBeenWarned ( )
1013+ expect ( node . value . isParam ( ) ) . toBe ( true )
1014+ if ( node . value . isParam ( ) ) {
1015+ expect ( node . value . pathParams ) . toHaveLength ( 1 )
1016+ expect ( node . value . pathParams [ 0 ] ) . toMatchObject ( {
1017+ paramName : 'pathMatch' ,
1018+ } )
1019+ }
1020+
1021+ // Empty param with prefix - gets default name
1022+ node = tree . insertParsedPath ( '/foo/:()' , 'test2.vue' )
1023+ expect (
1024+ 'Invalid parameter in path "/foo/:()": parameter name cannot be empty'
1025+ ) . toHaveBeenWarned ( )
1026+ expect ( node . value . isParam ( ) ) . toBe ( true )
1027+ if ( node . value . isParam ( ) ) {
1028+ expect ( node . value . pathParams ) . toHaveLength ( 1 )
1029+ expect ( node . value . pathParams [ 0 ] ) . toMatchObject ( {
1030+ paramName : 'pathMatch' ,
1031+ } )
1032+ }
1033+
1034+ // Mixed: valid param, empty param, valid param - empty gets default name
1035+ node = tree . insertParsedPath ( '/:a/:()/:b' , 'test3.vue' )
1036+ expect (
1037+ 'Invalid parameter in path "/:a/:()/:b": parameter name cannot be empty'
1038+ ) . toHaveBeenWarned ( )
1039+ expect ( node . value . isParam ( ) ) . toBe ( true )
1040+ if ( node . value . isParam ( ) ) {
1041+ expect ( node . value . pathParams ) . toHaveLength ( 3 )
1042+ expect ( node . value . pathParams [ 0 ] ) . toMatchObject ( { paramName : 'a' } )
1043+ expect ( node . value . pathParams [ 1 ] ) . toMatchObject ( {
1044+ paramName : 'pathMatch' ,
1045+ } )
1046+ expect ( node . value . pathParams [ 2 ] ) . toMatchObject ( { paramName : 'b' } )
1047+ }
1048+ } )
1049+ } )
9901050} )
0 commit comments