@@ -3,7 +3,6 @@ const DEFAULT_HEADERS = {
3
3
"Content-Type" : "application/json" ,
4
4
} ;
5
5
6
- const LEADING_QUESTION_RE = / ^ \? + / ;
7
6
const PATH_PARAM_RE = / \{ [ ^ { } ] + \} / g;
8
7
9
8
/**
@@ -19,7 +18,7 @@ export default function createClient(clientOptions) {
19
18
} = clientOptions ?? { } ;
20
19
let baseUrl = baseOptions . baseUrl ?? "" ;
21
20
if ( baseUrl . endsWith ( "/" ) ) {
22
- baseUrl = baseUrl . slice ( 0 , - 1 ) ; // remove trailing slash
21
+ baseUrl = baseUrl . substring ( 0 , baseUrl . length - 1 ) ;
23
22
}
24
23
25
24
/**
@@ -331,12 +330,8 @@ export function createQuerySerializer(options) {
331
330
* @see https://swagger.io/docs/specification/serialization/#path
332
331
*/
333
332
export function defaultPathSerializer ( pathname , pathParams ) {
334
- const matches = pathname . match ( PATH_PARAM_RE ) ;
335
- if ( ! matches || ! matches . length ) {
336
- return undefined ;
337
- }
338
333
let nextURL = pathname ;
339
- for ( const match of matches ) {
334
+ for ( const match of pathname . match ( PATH_PARAM_RE ) ?? [ ] ) {
340
335
let paramName = match . substring ( 1 , match . length - 1 ) ;
341
336
let explode = false ;
342
337
let style = "simple" ;
@@ -411,9 +406,10 @@ export function createFinalURL(pathname, options) {
411
406
if ( options . params ?. path ) {
412
407
finalURL = defaultPathSerializer ( finalURL , options . params . path ) ;
413
408
}
414
- const search = options
415
- . querySerializer ( options . params . query ?? { } )
416
- . replace ( LEADING_QUESTION_RE , "" ) ;
409
+ let search = options . querySerializer ( options . params . query ?? { } ) ;
410
+ if ( search . startsWith ( "?" ) ) {
411
+ search = search . substring ( 1 ) ;
412
+ }
417
413
if ( search ) {
418
414
finalURL += `?${ search } ` ;
419
415
}
0 commit comments