@@ -260,6 +260,42 @@ describe("client", () => {
260
260
) ;
261
261
} ) ;
262
262
263
+ it ( "escapes reserved characters in path segment" , async ( ) => {
264
+ const client = createClient < paths > ( { baseUrl } ) ;
265
+ const { getRequestUrl } = useMockRequestHandler ( {
266
+ baseUrl,
267
+ method : "get" ,
268
+ path : "/blogposts/*" ,
269
+ } ) ;
270
+
271
+ await client . GET ( "/blogposts/{post_id}" , {
272
+ params : { path : { post_id : ";/?:@&=+$,# " } } ,
273
+ } ) ;
274
+
275
+ // expect post_id to be encoded properly
276
+ const url = getRequestUrl ( ) ;
277
+ expect ( url . pathname ) . toBe ( "/blogposts/%3B%2F%3F%3A%40%26%3D%2B%24%2C%23%20" ) ;
278
+ } ) ;
279
+
280
+ it ( "does not escape allowed characters in path segment" , async ( ) => {
281
+ const client = createClient < paths > ( { baseUrl } ) ;
282
+ const { getRequestUrl } = useMockRequestHandler ( {
283
+ baseUrl,
284
+ method : "get" ,
285
+ path : "/blogposts/*" ,
286
+ } ) ;
287
+
288
+ const postId = "aAzZ09-_.!~*'()" ;
289
+
290
+ await client . GET ( "/blogposts/{post_id}" , {
291
+ params : { path : { post_id : postId } } ,
292
+ } ) ;
293
+
294
+ // expect post_id to stay unchanged
295
+ const url = getRequestUrl ( ) ;
296
+ expect ( url . pathname ) . toBe ( `/blogposts/${ postId } ` ) ;
297
+ } ) ;
298
+
263
299
it ( "allows UTF-8 characters" , async ( ) => {
264
300
const client = createClient < paths > ( { baseUrl } ) ;
265
301
const { getRequestUrl } = useMockRequestHandler ( {
@@ -269,13 +305,12 @@ describe("client", () => {
269
305
} ) ;
270
306
271
307
await client . GET ( "/blogposts/{post_id}" , {
272
- params : { path : { post_id : "post?id = 🥴" } } ,
308
+ params : { path : { post_id : "🥴" } } ,
273
309
} ) ;
274
310
275
311
// expect post_id to be encoded properly
276
312
const url = getRequestUrl ( ) ;
277
- expect ( url . searchParams . get ( "id " ) ) . toBe ( " 🥴" ) ;
278
- expect ( url . pathname + url . search ) . toBe ( "/blogposts/post?id%20=%20%F0%9F%A5%B4" ) ;
313
+ expect ( url . pathname ) . toBe ( "/blogposts/%F0%9F%A5%B4" ) ;
279
314
} ) ;
280
315
} ) ;
281
316
0 commit comments