Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Merge pull request #455 from DM-Francis/develop
Fix encoding when generating HTTP code snippets
Loading branch information
@@ -117,6 +117,30 @@ function convertPropertyListToString (propertyList, joinUsing, includeDisabled =
} ) , joinUsing ) ;
}
/**
* Url encodes the members of the property list.
*
* @param {Object } propertyList propertyList
* @param {String } joinUsing specify string that should be used to join the list of properties
* @param {Boolean } includeDisabled indicated whether or not to include disabled properties
* @param {Boolean } trimRequestBody indicates whether or not to trim request body
* @returns {String } Stringified and Url encoded property List
*/
function convertPropListToStringUrlEncoded ( propertyList , joinUsing , includeDisabled = false , trimRequestBody = false ) {
const properties = getMembersOfPropertyList ( propertyList , includeDisabled ) ,
keyvalues = [ ] ;
properties . forEach ( ( property ) => {
const key = trimRequestBody ? property . key . trim ( ) : property . key ,
value = trimRequestBody ? property . value . trim ( ) : property . value ,
keyvalue = `${ encodeURIComponent ( key ) } =${ encodeURIComponent ( value ) } ` ;
keyvalues . push ( keyvalue ) ;
} ) ;
return keyvalues . join ( joinUsing ) ;
}
/**
* Returns the request headers as a string
@@ -181,7 +205,8 @@ function getBody (request, trimRequestBody) {
case URL_ENCODED :
/* istanbul ignore else */
if ( ! _ . isEmpty ( request . body [ request . body . mode ] ) ) {
requestBody += convertPropertyListToString ( request . body [ request . body . mode ] , '&' , false , trimRequestBody ) ;
const propertyList = request . body [ request . body . mode ] ;
requestBody += convertPropListToStringUrlEncoded ( propertyList , '&' , false , trimRequestBody ) ;
}
return trimRequestBody ? requestBody . trim ( ) : requestBody ;
@@ -7,7 +7,7 @@
" POST /post HTTP/1.1\n Host: postman-echo.com\n Content-Length: 586\n Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW\n\n ----WebKitFormBoundary7MA4YWxkTrZu0gW\n Content-Disposition: form-data; name=\" pl\"\n\n 'a'\n ----WebKitFormBoundary7MA4YWxkTrZu0gW\n Content-Disposition: form-data; name=\" qu\"\n\n\" b\"\n ----WebKitFormBoundary7MA4YWxkTrZu0gW\n Content-Disposition: form-data; name=\" hdjkljh\"\n\n c\n ----WebKitFormBoundary7MA4YWxkTrZu0gW\n Content-Disposition: form-data; name=\" sa\"\n\n d\n ----WebKitFormBoundary7MA4YWxkTrZu0gW\n Content-Disposition: form-data; name=\" Special\"\n\n !@#$%&*()^_+=`~ \n ----WebKitFormBoundary7MA4YWxkTrZu0gW\n Content-Disposition: form-data; name=\" more\"\n\n ,./';[]}{\" :?><|\\\\\n ----WebKitFormBoundary7MA4YWxkTrZu0gW\n " ,
" POST /post?a=!@$^*()_-`%26&b=,./';[]}{\" :/?><|| HTTP/1.1\n Host: postman-echo.com" ,
" POST /post HTTP/1.1\n Host: postman-echo.com\n Content-Type: application/x-www-form-urlencoded\n Content-Length: 284\n\n Duis posuere augue vel cursus pharetra. In luctus a ex nec pretium. Praesent neque quam, tincidunt nec leo eget, rutrum vehicula magna.\n Maecenas consequat elementum elit, id semper sem tristique et. Integer pulvinar enim quis consectetur interdum volutpat.!@#$%^&*()+POL:},'';,[;[;\n\n\n " ,
" POST /post HTTP/1.1\n Host: postman-echo.com\n Content-Type: application/x-www-form-urlencoded\n Content-Length: 81 \n\n 1='a'&2=\" b \" &'3'=c&\" 4 \" =d&Special=!@%23$%% 26*()^_=`~ &more=,./';[]}{ \" :?><| \\\\ " ,
" POST /post HTTP/1.1\n Host: postman-echo.com\n Content-Type: application/x-www-form-urlencoded\n Content-Length: 147 \n\n 1='a'&2=%22b%22 &'3'=c&%224%22 =d&Special=!%40%23%24%25% 26*()%5E_%3D%60~%20%20%20%20 &more=%2C.%2F'%3B%5B%5D%7D%7B%22%3A%3F%3E%3C%7C%5C%5C%20%20%20%20 " ,
" POST /post HTTP/1.1\n Host: postman-echo.com\n Content-Type: application/json\n Content-Length: 52\n\n {\n \" json\" : \" Test-Test!@#$%^&*()+POL:},'';,[;[;:>\"\n }" ,
" POST /post HTTP/1.1\n Host: postman-echo.com\n Content-Type: application/javascript\n Content-Length: 30\n\n var val = 6;\n console.log(val);" ,
" POST /post HTTP/1.1\n Host: postman-echo.com\n Content-Type: text/xml\n Content-Length: 48\n\n <xml>\n\t Test Test!@#$%^&*()+POL:},'';,[;[;\n </xml>" ,
@@ -33,7 +33,7 @@
" trimmedResult" : [
" POST /post HTTP/1.1\n Host: postman-echo.com\n Content-Type: application/x-www-form-urlencoded\n Content-Length: 281\n\n Duis posuere augue vel cursus pharetra. In luctus a ex nec pretium. Praesent neque quam, tincidunt nec leo eget, rutrum vehicula magna.\n Maecenas consequat elementum elit, id semper sem tristique et. Integer pulvinar enim quis consectetur interdum volutpat.!@#$%^&*()+POL:},'';,[;[;" ,
" POST /post HTTP/1.1\n Host: postman-echo.com\n Content-Length: 581\n Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW\n\n ----WebKitFormBoundary7MA4YWxkTrZu0gW\n Content-Disposition: form-data; name=\" pl\"\n\n 'a'\n ----WebKitFormBoundary7MA4YWxkTrZu0gW\n Content-Disposition: form-data; name=\" qu\"\n\n\" b\"\n ----WebKitFormBoundary7MA4YWxkTrZu0gW\n Content-Disposition: form-data; name=\" hdjkljh\"\n\n c\n ----WebKitFormBoundary7MA4YWxkTrZu0gW\n Content-Disposition: form-data; name=\" sa\"\n\n d\n ----WebKitFormBoundary7MA4YWxkTrZu0gW\n Content-Disposition: form-data; name=\" Special\"\n\n !@#$%&*()^_+=`~\n ----WebKitFormBoundary7MA4YWxkTrZu0gW\n Content-Disposition: form-data; name=\" more\"\n\n ,./';[]}{\" :?><|\\\\\n ----WebKitFormBoundary7MA4YWxkTrZu0gW" ,
" POST /post HTTP/1.1\n Host: postman-echo.com\n Content-Type: application/x-www-form-urlencoded\n Content-Length: 73 \n\n 1='a'&2=\" b \" &'3'=c&\" 4 \" =d&Special=!@%23$%% 26*()^_=` ~&more=,./';[]}{ \" :?><| \\\\ "
" POST /post HTTP/1.1\n Host: postman-echo.com\n Content-Type: application/x-www-form-urlencoded\n Content-Length: 123 \n\n 1='a'&2=%22b%22 &'3'=c&%224%22 =d&Special=!%40%23%24%25% 26*()%5E_%3D%60 ~&more=%2C.%2F'%3B%5B%5D%7D%7B%22%3A%3F%3E%3C%7C%5C%5C "
]
}
Toggle all file notes
Toggle all file annotations