mirror of
https://github.com/usebruno/bruno.git
synced 2025-01-04 21:19:21 +01:00
Merge pull request #3706 from Pragadesh-45/fix/response-format-updates
fix: improve JSON parsing logic for `bruno-cli`
This commit is contained in:
commit
e897dc1eb0
@ -38,10 +38,14 @@ const parseDataFromResponse = (response, disableParsingResponseJson = false) =>
|
|||||||
// Filter out ZWNBSP character
|
// Filter out ZWNBSP character
|
||||||
// https://gist.github.com/antic183/619f42b559b78028d1fe9e7ae8a1352d
|
// https://gist.github.com/antic183/619f42b559b78028d1fe9e7ae8a1352d
|
||||||
data = data.replace(/^\uFEFF/, '');
|
data = data.replace(/^\uFEFF/, '');
|
||||||
if (!disableParsingResponseJson) {
|
|
||||||
|
// If the response is a string and starts and ends with double quotes, it's a stringified JSON and should not be parsed
|
||||||
|
if (!disableParsingResponseJson && !(typeof data === 'string' && data.startsWith('"') && data.endsWith('"'))) {
|
||||||
data = JSON.parse(data);
|
data = JSON.parse(data);
|
||||||
}
|
}
|
||||||
} catch { }
|
} catch {
|
||||||
|
console.log('Failed to parse response data as JSON');
|
||||||
|
}
|
||||||
|
|
||||||
return { data, dataBuffer };
|
return { data, dataBuffer };
|
||||||
};
|
};
|
||||||
|
@ -365,9 +365,9 @@ const parseDataFromResponse = (response, disableParsingResponseJson = false) =>
|
|||||||
try {
|
try {
|
||||||
// Filter out ZWNBSP character
|
// Filter out ZWNBSP character
|
||||||
// https://gist.github.com/antic183/619f42b559b78028d1fe9e7ae8a1352d
|
// https://gist.github.com/antic183/619f42b559b78028d1fe9e7ae8a1352d
|
||||||
|
data = data.replace(/^\uFEFF/, '');
|
||||||
|
|
||||||
// If the response is a string and starts and ends with double quotes, it's a stringified JSON and should not be parsed
|
// If the response is a string and starts and ends with double quotes, it's a stringified JSON and should not be parsed
|
||||||
data = data.replace(/^\uFEFF/, '');
|
|
||||||
if ( !disableParsingResponseJson && ! (typeof data === 'string' && data.startsWith("\"") && data.endsWith("\""))) {
|
if ( !disableParsingResponseJson && ! (typeof data === 'string' && data.startsWith("\"") && data.endsWith("\""))) {
|
||||||
data = JSON.parse(data);
|
data = JSON.parse(data);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user