@@ -206,6 +206,42 @@ describe("client", () => {
206
206
) ;
207
207
} ) ;
208
208
209
+ it ( "escapes reserved characters in path segment" , async ( ) => {
210
+ const client = createClient < paths > ( { baseUrl } ) ;
211
+ const { getRequestUrl } = useMockRequestHandler ( {
212
+ baseUrl,
213
+ method : "get" ,
214
+ path : "/blogposts/*" ,
215
+ } ) ;
216
+
217
+ await client . GET ( "/blogposts/{post_id}" , {
218
+ params : { path : { post_id : ";/?:@&=+$,# " } } ,
219
+ } ) ;
220
+
221
+ // expect post_id to be encoded properly
222
+ const url = getRequestUrl ( ) ;
223
+ expect ( url . pathname ) . toBe ( "/blogposts/%3B%2F%3F%3A%40%26%3D%2B%24%2C%23%20" ) ;
224
+ } ) ;
225
+
226
+ it ( "does not escape allowed characters in path segment" , async ( ) => {
227
+ const client = createClient < paths > ( { baseUrl } ) ;
228
+ const { getRequestUrl } = useMockRequestHandler ( {
229
+ baseUrl,
230
+ method : "get" ,
231
+ path : "/blogposts/*" ,
232
+ } ) ;
233
+
234
+ const postId = "aAzZ09-_.!~*'()" ;
235
+
236
+ await client . GET ( "/blogposts/{post_id}" , {
237
+ params : { path : { post_id : postId } } ,
238
+ } ) ;
239
+
240
+ // expect post_id to stay unchanged
241
+ const url = getRequestUrl ( ) ;
242
+ expect ( url . pathname ) . toBe ( `/blogposts/${ postId } ` ) ;
243
+ } ) ;
244
+
209
245
it ( "allows UTF-8 characters" , async ( ) => {
210
246
const client = createClient < paths > ( { baseUrl } ) ;
211
247
const { getRequestUrl } = useMockRequestHandler ( {
@@ -215,12 +251,12 @@ describe("client", () => {
215
251
} ) ;
216
252
217
253
await client . GET ( "/blogposts/{post_id}" , {
218
- params : { path : { post_id : "post?id = 🥴" } } ,
254
+ params : { path : { post_id : "🥴" } } ,
219
255
} ) ;
220
256
221
257
// expect post_id to be encoded properly
222
258
const url = getRequestUrl ( ) ;
223
- expect ( url . pathname ) . toBe ( "/blogposts/post%3Fid%20%3D%20 %F0%9F%A5%B4" ) ;
259
+ expect ( url . pathname ) . toBe ( "/blogposts/%F0%9F%A5%B4" ) ;
224
260
} ) ;
225
261
} ) ;
226
262
0 commit comments