Skip to content

Commit e56fb74

Browse files
authored
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
1 parent f05389c commit e56fb74

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

packages/bruno-electron/src/ipc/network/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,9 @@ const parseDataFromResponse = (response) => {
265265
let data = dataBuffer.toString(charset || 'utf-8');
266266
// Try to parse response to JSON, this can quietly fail
267267
try {
268-
data = JSON.parse(response.data);
268+
// Filter out control characters and ZWNBSP character
269+
data = data.replace(/[\x00-\x08\x0E-\x1F\x7F\uFEFF]/g, '');
270+
data = JSON.parse(data);
269271
} catch {}
270272

271273
return { data, dataBuffer };
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
meta {
2+
name: echo bom json
3+
type: http
4+
seq: 1
5+
}
6+
7+
get {
8+
url: {{host}}/api/echo/bom-json-test
9+
body: none
10+
auth: none
11+
}

packages/bruno-tests/src/echo/index.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,16 @@ router.post('/xml-raw', (req, res) => {
1919
return res.send(req.rawBody);
2020
});
2121

22+
router.get('/bom-json-test', (req, res) => {
23+
const jsonData = {
24+
message: 'Hello!',
25+
success: true
26+
};
27+
const jsonString = JSON.stringify(jsonData);
28+
const bom = '\uFEFF';
29+
const jsonWithBom = bom + jsonString;
30+
res.set('Content-Type', 'application/json; charset=utf-8');
31+
return res.send(jsonWithBom);
32+
});
33+
2234
module.exports = router;

0 commit comments

Comments
 (0)