fix: unable to set request bodies with colon characters in their names

This commit is contained in:
Mateusz Pietryga 2024-09-23 19:29:51 +02:00
parent d64dffe7fa
commit 3a8922aad9
No known key found for this signature in database
GPG Key ID: 549A107FB8327670
3 changed files with 32 additions and 6 deletions

View File

@ -105,7 +105,7 @@ const jsonToBru = (json) => {
if (enabled(headers).length) { if (enabled(headers).length) {
bru += `\n${indentString( bru += `\n${indentString(
enabled(headers) enabled(headers)
.map((item) => `${item.name}: ${item.value}`) .map((item) => `${quoteKey(item.name)}: ${item.value}`)
.join('\n') .join('\n')
)}`; )}`;
} }
@ -113,7 +113,7 @@ const jsonToBru = (json) => {
if (disabled(headers).length) { if (disabled(headers).length) {
bru += `\n${indentString( bru += `\n${indentString(
disabled(headers) disabled(headers)
.map((item) => `~${item.name}: ${item.value}`) .map((item) => `~${quoteKey(item.name)}: ${item.value}`)
.join('\n') .join('\n')
)}`; )}`;
} }
@ -260,14 +260,14 @@ ${indentString(body.sparql)}
if (enabled(body.formUrlEncoded).length) { if (enabled(body.formUrlEncoded).length) {
const enabledValues = enabled(body.formUrlEncoded) const enabledValues = enabled(body.formUrlEncoded)
.map((item) => `${item.name}: ${getValueString(item.value)}`) .map((item) => `${quoteKey(item.name)}: ${getValueString(item.value)}`)
.join('\n'); .join('\n');
bru += `${indentString(enabledValues)}\n`; bru += `${indentString(enabledValues)}\n`;
} }
if (disabled(body.formUrlEncoded).length) { if (disabled(body.formUrlEncoded).length) {
const disabledValues = disabled(body.formUrlEncoded) const disabledValues = disabled(body.formUrlEncoded)
.map((item) => `~${item.name}: ${getValueString(item.value)}`) .map((item) => `~${quoteKey(item.name)}: ${getValueString(item.value)}`)
.join('\n'); .join('\n');
bru += `${indentString(disabledValues)}\n`; bru += `${indentString(disabledValues)}\n`;
} }
@ -285,14 +285,14 @@ ${indentString(body.sparql)}
.map((item) => { .map((item) => {
const enabled = item.enabled ? '' : '~'; const enabled = item.enabled ? '' : '~';
if (item.type === 'text') { if (item.type === 'text') {
return `${enabled}${item.name}: ${getValueString(item.value)}`; return `${enabled}${quoteKey(item.name)}: ${getValueString(item.value)}`;
} }
if (item.type === 'file') { if (item.type === 'file') {
let filepaths = item.value || []; let filepaths = item.value || [];
let filestr = filepaths.join('|'); let filestr = filepaths.join('|');
const value = `@file(${filestr})`; const value = `@file(${filestr})`;
return `${enabled}${item.name}: ${value}`; return `${enabled}${quoteKey(item.name)}: ${value}`;
} }
}) })
.join('\n') .join('\n')

View File

@ -96,13 +96,17 @@ body:sparql {
body:form-urlencoded { body:form-urlencoded {
apikey: secret apikey: secret
numbers: +91998877665 numbers: +91998877665
"colon:parameter": is allowed
~message: hello ~message: hello
~"disabled colon:parameter": is allowed
} }
body:multipart-form { body:multipart-form {
apikey: secret apikey: secret
numbers: +91998877665 numbers: +91998877665
"colon:part": is allowed
~message: hello ~message: hello
~"disabled colon:part": is allowed
} }
body:graphql { body:graphql {

View File

@ -127,10 +127,20 @@
"value": "+91998877665", "value": "+91998877665",
"enabled": true "enabled": true
}, },
{
"name": "colon:parameter",
"value": "is allowed",
"enabled": true
},
{ {
"name": "message", "name": "message",
"value": "hello", "value": "hello",
"enabled": false "enabled": false
},
{
"name": "disabled colon:parameter",
"value": "is allowed",
"enabled": false
} }
], ],
"multipartForm": [ "multipartForm": [
@ -146,11 +156,23 @@
"enabled": true, "enabled": true,
"type": "text" "type": "text"
}, },
{
"name": "colon:part",
"value": "is allowed",
"enabled": true,
"type": "text"
},
{ {
"name": "message", "name": "message",
"value": "hello", "value": "hello",
"enabled": false, "enabled": false,
"type": "text" "type": "text"
},
{
"name": "disabled colon:part",
"value": "is allowed",
"enabled": false,
"type": "text"
} }
] ]
}, },