Skip to content

Commit 8080954

Browse files
committed
Added the formdata fix in csharp-restsharp and added the test back to main collection
1 parent 0b1bab3 commit 8080954

File tree

2 files changed

+86
-0
lines changed

2 files changed

+86
-0
lines changed

codegens/csharp-restsharp/lib/restsharp.js

+13
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,19 @@ function makeSnippet (request, options) {
3030
}
3131
snippet += `var request = new RestRequest(${isUnSupportedMethod ? '' : ('Method.' + request.method)});\n`;
3232
snippet += parseRequest.parseHeader(request.toJSON(), options.trimRequestBody);
33+
if (request.body && request.body.mode === 'formdata') {
34+
let isFile = false;
35+
request.body.toJSON().formdata.forEach((data) => {
36+
if (!data.disabled && data.type === 'file') {
37+
isFile = true;
38+
}
39+
});
40+
// The following statement needs to be added else the multipart/form-data request where there is no file
41+
// is being sent as x-www-form-urlencoded by default
42+
if (!isFile) {
43+
snippet += 'request.AlwaysMultipartFormData = true;\n';
44+
}
45+
}
3346
snippet += parseRequest.parseBody(request, options.trimRequestBody);
3447
if (isUnSupportedMethod) {
3548
(UNSUPPORTED_METHODS_LIKE_GET.includes(request.method)) &&

test/codegen/newman/fixtures/testCollection.json

+73
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,79 @@
403403
},
404404
"response": []
405405
},
406+
{
407+
"name": "POST form data with special characters",
408+
"event": [
409+
{
410+
"listen": "test",
411+
"script": {
412+
"id": "111c859c-4a8c-41e6-b404-9c404609811b",
413+
"exec": [
414+
""
415+
],
416+
"type": "text/javascript"
417+
}
418+
}
419+
],
420+
"request": {
421+
"method": "POST",
422+
"header": [],
423+
"body": {
424+
"mode": "formdata",
425+
"formdata": [
426+
{
427+
"key": "pl",
428+
"value": "'a'",
429+
"type": "text"
430+
},
431+
{
432+
"key": "qu",
433+
"value": "\"b\"",
434+
"type": "text"
435+
},
436+
{
437+
"key": "hdjkljh",
438+
"value": "c",
439+
"type": "text"
440+
},
441+
{
442+
"key": "sa",
443+
"value": "d",
444+
"type": "text"
445+
},
446+
{
447+
"key": "Special",
448+
"value": "!@#$%&*()^_+=`~",
449+
"type": "text"
450+
},
451+
{
452+
"key": "Not Select",
453+
"value": "Disabled",
454+
"type": "text",
455+
"disabled": true
456+
},
457+
{
458+
"key": "more",
459+
"value": ",./';[]}{\":?><|\\\\",
460+
"type": "text"
461+
}
462+
]
463+
},
464+
"url": {
465+
"raw": "https://postman-echo.com/post",
466+
"protocol": "https",
467+
"host": [
468+
"postman-echo",
469+
"com"
470+
],
471+
"path": [
472+
"post"
473+
]
474+
},
475+
"description": "The HTTP `POST` request method is meant to transfer data to a server \n(and elicit a response). What data is returned depends on the implementation\nof the server.\n\nA `POST` request can pass parameters to the server using \"Query String \nParameters\", as well as the Request Body. For example, in the following request,\n\n> POST /hi/there?hand=wave\n>\n> <request-body>\n\nThe parameter \"hand\" has the value \"wave\". The request body can be in multiple\nformats. These formats are defined by the MIME type of the request. The MIME \nType can be set using the ``Content-Type`` HTTP header. The most commonly used \nMIME types are:\n\n* `multipart/form-data`\n* `application/x-www-form-urlencoded`\n* `application/json`\n\nThis endpoint echoes the HTTP headers, request parameters, the contents of\nthe request body and the complete URI requested."
476+
},
477+
"response": []
478+
},
406479
{
407480
"name": "PUT Request",
408481
"event": [

0 commit comments

Comments
 (0)