@@ -66,6 +66,13 @@ describe('Routes', () => {
66
66
expect ( query ) . not . toHaveProperty ( 'a' )
67
67
} )
68
68
69
+ test ( 'match and merge escaped params' , ( ) => {
70
+ const routes = nextRoutes ( ) . add ( 'a' , '/a/:b' )
71
+ const { query} = routes . match ( '/a/b%20%2F%20b' )
72
+ expect ( query ) . toMatchObject ( { b : 'b / b' } )
73
+ expect ( query ) . not . toHaveProperty ( 'a' )
74
+ } )
75
+
69
76
test ( 'generate urls from params' , ( ) => {
70
77
const { route} = setup ( 'a' , '/a/:b/:c+' )
71
78
const params = { b : 'b' , c : [ 1 , 2 ] , d : 'd' }
@@ -74,6 +81,14 @@ describe('Routes', () => {
74
81
expect ( setup ( 'a' ) . route . getUrls ( ) ) . toEqual ( { as : '/a' , href : '/a?' } )
75
82
} )
76
83
84
+ test ( 'generate urls with params that need escaping' , ( ) => {
85
+ const { route} = setup ( 'a' , '/a/:b' )
86
+ const params = { b : 'b b' }
87
+ const expected = { as : '/a/b%20b' , href : '/a?b=b%20b' }
88
+ expect ( route . getUrls ( params ) ) . toEqual ( expected )
89
+ expect ( setup ( 'a' ) . route . getUrls ( ) ) . toEqual ( { as : '/a' , href : '/a?' } )
90
+ } )
91
+
77
92
test ( 'do not pass "null" for params that have null values' , ( ) => {
78
93
const { route} = setup ( 'a' , '/a/:b/:c?' )
79
94
const params = { b : 'b' , c : null , d : undefined }
0 commit comments