mirror of
https://github.com/usebruno/bruno.git
synced 2024-11-07 08:34: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') {
|
||||
if (typeof request.data === 'object') {
|
||||
try {
|
||||
let parsed = JSON.stringify(request.data);
|
||||
parsed = _interpolate(parsed);
|
||||
request.data = JSON.parse(parsed);
|
||||
forOwn(request?.data, (value, key) => {
|
||||
request.data[key] = _interpolate(value);
|
||||
});
|
||||
} catch (err) {}
|
||||
}
|
||||
} else if (contentType === 'multipart/form-data') {
|
||||
if (typeof request.data === 'object' && !(request?.data instanceof FormData)) {
|
||||
try {
|
||||
let parsed = JSON.stringify(request.data);
|
||||
parsed = _interpolate(parsed);
|
||||
request.data = JSON.parse(parsed);
|
||||
forOwn(request?.data, (value, key) => {
|
||||
request.data[key] = _interpolate(value);
|
||||
});
|
||||
} catch (err) {}
|
||||
}
|
||||
} else {
|
||||
|
@ -78,17 +78,17 @@ const interpolateVars = (request, envVariables = {}, runtimeVariables = {}, proc
|
||||
} else if (contentType === 'application/x-www-form-urlencoded') {
|
||||
if (typeof request.data === 'object') {
|
||||
try {
|
||||
let parsed = JSON.stringify(request.data);
|
||||
parsed = _interpolate(parsed);
|
||||
request.data = JSON.parse(parsed);
|
||||
forOwn(request?.data, (value, key) => {
|
||||
request.data[key] = _interpolate(value);
|
||||
});
|
||||
} catch (err) {}
|
||||
}
|
||||
} else if (contentType === 'multipart/form-data') {
|
||||
if (typeof request.data === 'object' && !(request.data instanceof FormData)) {
|
||||
try {
|
||||
let parsed = JSON.stringify(request.data);
|
||||
parsed = _interpolate(parsed);
|
||||
request.data = JSON.parse(parsed);
|
||||
forOwn(request?.data, (value, key) => {
|
||||
request.data[key] = _interpolate(value);
|
||||
});
|
||||
} catch (err) {}
|
||||
}
|
||||
} else {
|
||||
|
@ -12,12 +12,15 @@ post {
|
||||
|
||||
body:form-urlencoded {
|
||||
form-data-key: {{form-data-key}}
|
||||
}
|
||||
|
||||
script:pre-request {
|
||||
bru.setVar('form-data-key', 'form-data-value');
|
||||
form-data-stringified-object: {{form-data-stringified-object}}
|
||||
}
|
||||
|
||||
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 {
|
||||
foo: {{form-data-key}}
|
||||
form-data-key: {{form-data-key}}
|
||||
form-data-stringified-object: {{form-data-stringified-object}}
|
||||
file: @file(bruno.png)
|
||||
}
|
||||
|
||||
assert {
|
||||
res.body: contains form-data-value
|
||||
res.body: contains {"foo":123}
|
||||
}
|
||||
|
||||
script:pre-request {
|
||||
let obj = JSON.stringify({foo:123});
|
||||
bru.setVar('form-data-key', 'form-data-value');
|
||||
bru.setVar('form-data-stringified-object', obj);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user