@@ -23,8 +23,8 @@ self = module.exports = {
2323 format = options . longFormat ;
2424 trim = options . trimRequestBody ;
2525 silent = options . silent ;
26- url = getUrlStringfromUrlObject ( request . url ) ;
2726 quoteType = options . quoteType === 'single' ? '\'' : '"' ;
27+ url = getUrlStringfromUrlObject ( request . url , quoteType ) ;
2828
2929 snippet = silent ? `curl ${ form ( '-s' , format ) } ` : 'curl' ;
3030
@@ -72,14 +72,14 @@ self = module.exports = {
7272 if ( ! header . key ) {
7373 return ;
7474 }
75- snippet += indent + `${ form ( '-H' , format ) } ' ${ sanitize ( header . key , true ) } ` ;
75+ snippet += indent + `${ form ( '-H' , format ) } ${ quoteType } ${ sanitize ( header . key , true , quoteType ) } ` ;
7676 // If the header value is an empty string then add a semicolon after key
7777 // otherwise the header would be ignored by curl
7878 if ( header . value ) {
79- snippet += `: ${ sanitize ( header . value ) } ' ` ;
79+ snippet += `: ${ sanitize ( header . value , false , quoteType ) } ${ quoteType } ` ;
8080 }
8181 else {
82- snippet += ';\'' ;
82+ snippet += ';' + quoteType ;
8383 }
8484 } ) ;
8585 }
@@ -130,12 +130,13 @@ self = module.exports = {
130130 // Using the long form below without considering the longFormat option,
131131 // to generate more accurate and correct snippet
132132 snippet += indent + '--data-urlencode' ;
133- snippet += ` '${ sanitize ( data . key , trim ) } =${ sanitize ( data . value , trim ) } '` ;
133+ snippet += ` ${ quoteType } ${ sanitize ( data . key , trim , quoteType ) } =` +
134+ `${ sanitize ( data . value , trim , quoteType ) } ${ quoteType } ` ;
134135 }
135136 } ) ;
136137 break ;
137138 case 'raw' :
138- snippet += indent + `--data-raw ' ${ sanitize ( body . raw . toString ( ) , trim ) } ' ` ;
139+ snippet += indent + `--data-raw ${ quoteType } ${ sanitize ( body . raw . toString ( ) , trim , quoteType ) } ${ quoteType } ` ;
139140 break ;
140141 case 'graphql' :
141142 // eslint-disable-next-line no-case-declarations
@@ -147,35 +148,38 @@ self = module.exports = {
147148 catch ( e ) {
148149 graphqlVariables = { } ;
149150 }
150- snippet += indent + `--data-raw ' ${ sanitize ( JSON . stringify ( {
151+ snippet += indent + `--data-raw ${ quoteType } ${ sanitize ( JSON . stringify ( {
151152 query : query ,
152153 variables : graphqlVariables
153- } ) , trim ) } ' `;
154+ } ) , trim , quoteType ) } ${ quoteType } `;
154155 break ;
155156 case 'formdata' :
156157 _ . forEach ( body . formdata , function ( data ) {
157158 if ( ! ( data . disabled ) ) {
158159 if ( data . type === 'file' ) {
159160 snippet += indent + `${ form ( '-F' , format ) } ` ;
160- snippet += ` '${ sanitize ( data . key , trim ) } =@"${ sanitize ( data . src , trim , true , true ) } "'` ;
161+ snippet += ` ${ quoteType } ${ sanitize ( data . key , trim , quoteType ) } =` +
162+ `${ sanitize ( `@"${ sanitize ( data . src , trim , '"' , true ) } "` , trim , quoteType , quoteType === '"' ) } ` ;
163+ snippet += quoteType ;
161164 }
162165 else {
163166 snippet += indent + `${ form ( '-F' , format ) } ` ;
164- snippet += ` '${ sanitize ( data . key , trim ) } ="${ sanitize ( data . value , trim , true , true ) } "` ;
167+ snippet += ` ${ quoteType } ${ sanitize ( data . key , trim , quoteType ) } =` +
168+ sanitize ( `"${ sanitize ( data . value , trim , '"' , true ) } "` , trim , quoteType , quoteType === '"' ) ;
165169 if ( data . contentType ) {
166170 snippet += `;type=${ data . contentType } ` ;
167171 }
168- snippet += '\'' ;
172+ snippet += quoteType ;
169173 }
170174 }
171175 } ) ;
172176 break ;
173177 case 'file' :
174178 snippet += indent + '--data-binary' ;
175- snippet += ` ' @${ sanitize ( body [ body . mode ] . src , trim ) } ' ` ;
179+ snippet += ` ${ quoteType } @${ sanitize ( body [ body . mode ] . src , trim ) } ${ quoteType } ` ;
176180 break ;
177181 default :
178- snippet += `${ form ( '-d' , format ) } '' ` ;
182+ snippet += `${ form ( '-d' , format ) } ${ quoteType } ${ quoteType } ` ;
179183 }
180184 }
181185 }
0 commit comments