Skip to content
This repository has been archived by the owner on Nov 22, 2024. It is now read-only.

Commit

Permalink
correctly handle gzipped unicode fixes 394
Browse files Browse the repository at this point in the history
Summary:
For gzipped requests, the decoding of unicode characters was failing, because it was was done, before decompressing the response payload.

In this diff, the payload is first decompressed and decoded afterwards. For the calculation of the response size, this is removed, because it doesn't matter for the calculation of the size to correctly decode unicode characters. However, there might be a problem with displaying the correct size. This is tracked in T41427687.

Reviewed By: jknoxville

Differential Revision: D14366841

fbshipit-source-id: e375df1ec44505f6315dedbe71b3b62eac0f281a
  • Loading branch information
danielbuechele authored and facebook-github-bot committed Mar 7, 2019
1 parent 83c9d33 commit 2c05fdf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
14 changes: 9 additions & 5 deletions src/plugins/network/RequestDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,15 @@ function decodeBody(container: Request | Response): string {
if (!container.data) {
return '';
}
const b64Decoded = decodeURIComponent(escape(atob(container.data)));

return getHeaderValue(container.headers, 'Content-Encoding') === 'gzip'
? decompress(b64Decoded)
: b64Decoded;
const b64Decoded = atob(container.data);
const body =
getHeaderValue(container.headers, 'Content-Encoding') === 'gzip'
? decompress(b64Decoded)
: b64Decoded;

// Data is transferred as base64 encoded bytes to support unicode characters,
// we need to decode the bytes here to display the correct unicode characters.
return decodeURIComponent(escape(body));
}

function decompress(body: string): string {
Expand Down
5 changes: 4 additions & 1 deletion src/plugins/network/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,10 @@ class SizeColumn extends PureComponent<{
if (lengthString != null && lengthString != '') {
length = parseInt(lengthString, 10);
} else if (response.data) {
length = decodeURIComponent(escape(atob(response.data))).length;
// FIXME: T41427687 This is probably not the correct way to determine
// the correct byte size of the response, because String.length returns
// the number of characters, not bytes.
length = atob(response.data).length;
}
return length;
}
Expand Down

0 comments on commit 2c05fdf

Please sign in to comment.