mirror of
https://github.com/usebruno/bruno.git
synced 2024-11-25 09:23:17 +01:00
Filter out non-printable characters, control characters and ZWNBSP character from the response body (#2346)
* fix(#1003): content type for client_credentials & password grant types * feature(#1003): added client is & secret for password credentials grant type * fix: filter out non-printable control character and ZWNBSP character * fix: filter out non-printable control character and ZWNBSP character
This commit is contained in:
parent
f05389ca72
commit
e56fb74801
@ -265,7 +265,9 @@ const parseDataFromResponse = (response) => {
|
||||
let data = dataBuffer.toString(charset || 'utf-8');
|
||||
// Try to parse response to JSON, this can quietly fail
|
||||
try {
|
||||
data = JSON.parse(response.data);
|
||||
// Filter out control characters and ZWNBSP character
|
||||
data = data.replace(/[\x00-\x08\x0E-\x1F\x7F\uFEFF]/g, '');
|
||||
data = JSON.parse(data);
|
||||
} catch {}
|
||||
|
||||
return { data, dataBuffer };
|
||||
|
11
packages/bruno-tests/collection/echo/echo bom json.bru
Normal file
11
packages/bruno-tests/collection/echo/echo bom json.bru
Normal file
@ -0,0 +1,11 @@
|
||||
meta {
|
||||
name: echo bom json
|
||||
type: http
|
||||
seq: 1
|
||||
}
|
||||
|
||||
get {
|
||||
url: {{host}}/api/echo/bom-json-test
|
||||
body: none
|
||||
auth: none
|
||||
}
|
@ -19,4 +19,16 @@ router.post('/xml-raw', (req, res) => {
|
||||
return res.send(req.rawBody);
|
||||
});
|
||||
|
||||
router.get('/bom-json-test', (req, res) => {
|
||||
const jsonData = {
|
||||
message: 'Hello!',
|
||||
success: true
|
||||
};
|
||||
const jsonString = JSON.stringify(jsonData);
|
||||
const bom = '\uFEFF';
|
||||
const jsonWithBom = bom + jsonString;
|
||||
res.set('Content-Type', 'application/json; charset=utf-8');
|
||||
return res.send(jsonWithBom);
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
|
Loading…
Reference in New Issue
Block a user