Skip to content

Commit

Permalink
fix: Filter out the ZWNBSP character from response body, fixed charse…
Browse files Browse the repository at this point in the history
…t parse logic (usebruno#2351)

* fix(usebruno#1003): content type for client_credentials & password grant types

* feature(usebruno#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

* remove ZWNBSP character from response body

---------

Co-authored-by: Anoop M D <anoop.md1421@gmail.com>
  • Loading branch information
2 people authored and jwetzell committed Aug 2, 2024
1 parent 1f51146 commit 9af47e9
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions packages/bruno-electron/src/ipc/network/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,13 +260,16 @@ const configureRequest = async (
const parseDataFromResponse = (response) => {
const dataBuffer = Buffer.from(response.data);
// Parse the charset from content type: https://stackoverflow.com/a/33192813
const charset = /charset=([^()<>@,;:"/[\]?.=\s]*)/i.exec(response.headers['Content-Type'] || '');
const charsetMatch = /charset=([^()<>@,;:"/[\]?.=\s]*)/i.exec(response.headers['content-type'] || '');
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec#using_exec_with_regexp_literals
const charsetValue = charsetMatch?.[1];
// Overwrite the original data for backwards compatibility
let data = dataBuffer.toString(charset || 'utf-8');
let data = dataBuffer.toString(charsetValue || 'utf-8');
// Try to parse response to JSON, this can quietly fail
try {
// Filter out control characters and ZWNBSP character
data = data.replace(/[\x00-\x08\x0E-\x1F\x7F\uFEFF]/g, '');
// Filter out ZWNBSP character
// https://gist.github.com/antic183/619f42b559b78028d1fe9e7ae8a1352d
data = data.replace(/^\uFEFF/, '');
data = JSON.parse(data);
} catch {}

Expand Down

0 comments on commit 9af47e9

Please sign in to comment.