Skip to content

Commit

Permalink
fix: unable to set request bodies with colon characters in their names
Browse files Browse the repository at this point in the history
  • Loading branch information
pietrygamat committed Sep 23, 2024
1 parent d64dffe commit 3a8922a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
12 changes: 6 additions & 6 deletions packages/bruno-lang/v2/src/jsonToBru.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,15 @@ const jsonToBru = (json) => {
if (enabled(headers).length) {
bru += `\n${indentString(
enabled(headers)
.map((item) => `${item.name}: ${item.value}`)
.map((item) => `${quoteKey(item.name)}: ${item.value}`)
.join('\n')
)}`;
}

if (disabled(headers).length) {
bru += `\n${indentString(
disabled(headers)
.map((item) => `~${item.name}: ${item.value}`)
.map((item) => `~${quoteKey(item.name)}: ${item.value}`)
.join('\n')
)}`;
}
Expand Down Expand Up @@ -260,14 +260,14 @@ ${indentString(body.sparql)}

if (enabled(body.formUrlEncoded).length) {
const enabledValues = enabled(body.formUrlEncoded)
.map((item) => `${item.name}: ${getValueString(item.value)}`)
.map((item) => `${quoteKey(item.name)}: ${getValueString(item.value)}`)
.join('\n');
bru += `${indentString(enabledValues)}\n`;
}

if (disabled(body.formUrlEncoded).length) {
const disabledValues = disabled(body.formUrlEncoded)
.map((item) => `~${item.name}: ${getValueString(item.value)}`)
.map((item) => `~${quoteKey(item.name)}: ${getValueString(item.value)}`)
.join('\n');
bru += `${indentString(disabledValues)}\n`;
}
Expand All @@ -285,14 +285,14 @@ ${indentString(body.sparql)}
.map((item) => {
const enabled = item.enabled ? '' : '~';
if (item.type === 'text') {
return `${enabled}${item.name}: ${getValueString(item.value)}`;
return `${enabled}${quoteKey(item.name)}: ${getValueString(item.value)}`;
}
if (item.type === 'file') {
let filepaths = item.value || [];
let filestr = filepaths.join('|');
const value = `@file(${filestr})`;
return `${enabled}${item.name}: ${value}`;
return `${enabled}${quoteKey(item.name)}: ${value}`;
}
})
.join('\n')
Expand Down
4 changes: 4 additions & 0 deletions packages/bruno-lang/v2/tests/fixtures/request.bru
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,17 @@ body:sparql {
body:form-urlencoded {
apikey: secret
numbers: +91998877665
"colon:parameter": is allowed
~message: hello
~"disabled colon:parameter": is allowed
}

body:multipart-form {
apikey: secret
numbers: +91998877665
"colon:part": is allowed
~message: hello
~"disabled colon:part": is allowed
}

body:graphql {
Expand Down
22 changes: 22 additions & 0 deletions packages/bruno-lang/v2/tests/fixtures/request.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,20 @@
"value": "+91998877665",
"enabled": true
},
{
"name": "colon:parameter",
"value": "is allowed",
"enabled": true
},
{
"name": "message",
"value": "hello",
"enabled": false
},
{
"name": "disabled colon:parameter",
"value": "is allowed",
"enabled": false
}
],
"multipartForm": [
Expand All @@ -146,11 +156,23 @@
"enabled": true,
"type": "text"
},
{
"name": "colon:part",
"value": "is allowed",
"enabled": true,
"type": "text"
},
{
"name": "message",
"value": "hello",
"enabled": false,
"type": "text"
},
{
"name": "disabled colon:part",
"value": "is allowed",
"enabled": false,
"type": "text"
}
]
},
Expand Down

0 comments on commit 3a8922a

Please sign in to comment.