mirror of
https://github.com/usebruno/bruno.git
synced 2024-11-21 23:43:15 +01:00
fix: interpolate form-urlencoded and multipart formdata values individually (#3237)
* fix: interpolate form-urlencoded and multipart values individually * feat: cli updates
This commit is contained in:
parent
95e56cd9c9
commit
4797119657
@ -74,17 +74,17 @@ const interpolateVars = (request, envVars = {}, runtimeVariables = {}, processEn
|
|||||||
} else if (contentType === 'application/x-www-form-urlencoded') {
|
} else if (contentType === 'application/x-www-form-urlencoded') {
|
||||||
if (typeof request.data === 'object') {
|
if (typeof request.data === 'object') {
|
||||||
try {
|
try {
|
||||||
let parsed = JSON.stringify(request.data);
|
forOwn(request?.data, (value, key) => {
|
||||||
parsed = _interpolate(parsed);
|
request.data[key] = _interpolate(value);
|
||||||
request.data = JSON.parse(parsed);
|
});
|
||||||
} catch (err) {}
|
} catch (err) {}
|
||||||
}
|
}
|
||||||
} else if (contentType === 'multipart/form-data') {
|
} else if (contentType === 'multipart/form-data') {
|
||||||
if (typeof request.data === 'object' && !(request?.data instanceof FormData)) {
|
if (typeof request.data === 'object' && !(request?.data instanceof FormData)) {
|
||||||
try {
|
try {
|
||||||
let parsed = JSON.stringify(request.data);
|
forOwn(request?.data, (value, key) => {
|
||||||
parsed = _interpolate(parsed);
|
request.data[key] = _interpolate(value);
|
||||||
request.data = JSON.parse(parsed);
|
});
|
||||||
} catch (err) {}
|
} catch (err) {}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -78,17 +78,17 @@ const interpolateVars = (request, envVariables = {}, runtimeVariables = {}, proc
|
|||||||
} else if (contentType === 'application/x-www-form-urlencoded') {
|
} else if (contentType === 'application/x-www-form-urlencoded') {
|
||||||
if (typeof request.data === 'object') {
|
if (typeof request.data === 'object') {
|
||||||
try {
|
try {
|
||||||
let parsed = JSON.stringify(request.data);
|
forOwn(request?.data, (value, key) => {
|
||||||
parsed = _interpolate(parsed);
|
request.data[key] = _interpolate(value);
|
||||||
request.data = JSON.parse(parsed);
|
});
|
||||||
} catch (err) {}
|
} catch (err) {}
|
||||||
}
|
}
|
||||||
} else if (contentType === 'multipart/form-data') {
|
} else if (contentType === 'multipart/form-data') {
|
||||||
if (typeof request.data === 'object' && !(request.data instanceof FormData)) {
|
if (typeof request.data === 'object' && !(request.data instanceof FormData)) {
|
||||||
try {
|
try {
|
||||||
let parsed = JSON.stringify(request.data);
|
forOwn(request?.data, (value, key) => {
|
||||||
parsed = _interpolate(parsed);
|
request.data[key] = _interpolate(value);
|
||||||
request.data = JSON.parse(parsed);
|
});
|
||||||
} catch (err) {}
|
} catch (err) {}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -12,12 +12,15 @@ post {
|
|||||||
|
|
||||||
body:form-urlencoded {
|
body:form-urlencoded {
|
||||||
form-data-key: {{form-data-key}}
|
form-data-key: {{form-data-key}}
|
||||||
}
|
form-data-stringified-object: {{form-data-stringified-object}}
|
||||||
|
|
||||||
script:pre-request {
|
|
||||||
bru.setVar('form-data-key', 'form-data-value');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
assert {
|
assert {
|
||||||
res.body: eq form-data-key=form-data-value
|
res.body: eq form-data-key=form-data-value&form-data-stringified-object=%7B%22foo%22%3A123%7D
|
||||||
|
}
|
||||||
|
|
||||||
|
script:pre-request {
|
||||||
|
let obj = JSON.stringify({foo:123});
|
||||||
|
bru.setVar('form-data-key', 'form-data-value');
|
||||||
|
bru.setVar('form-data-stringified-object', obj);
|
||||||
}
|
}
|
||||||
|
@ -11,14 +11,18 @@ post {
|
|||||||
}
|
}
|
||||||
|
|
||||||
body:multipart-form {
|
body:multipart-form {
|
||||||
foo: {{form-data-key}}
|
form-data-key: {{form-data-key}}
|
||||||
|
form-data-stringified-object: {{form-data-stringified-object}}
|
||||||
file: @file(bruno.png)
|
file: @file(bruno.png)
|
||||||
}
|
}
|
||||||
|
|
||||||
assert {
|
assert {
|
||||||
res.body: contains form-data-value
|
res.body: contains form-data-value
|
||||||
|
res.body: contains {"foo":123}
|
||||||
}
|
}
|
||||||
|
|
||||||
script:pre-request {
|
script:pre-request {
|
||||||
|
let obj = JSON.stringify({foo:123});
|
||||||
bru.setVar('form-data-key', 'form-data-value');
|
bru.setVar('form-data-key', 'form-data-value');
|
||||||
|
bru.setVar('form-data-stringified-object', obj);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user