Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter out non-printable characters, control characters and ZWNBSP character from the response body #2346

Merged
merged 5 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/bruno-electron/src/ipc/network/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down
11 changes: 11 additions & 0 deletions packages/bruno-tests/collection/echo/echo bom json.bru
Original file line number Diff line number Diff line change
@@ -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
}
12 changes: 12 additions & 0 deletions packages/bruno-tests/src/echo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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