From 2c05fdf347e6e5e3571623fd456db531dd19feae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20B=C3=BCchele?= Date: Thu, 7 Mar 2019 09:59:06 -0800 Subject: [PATCH] correctly handle gzipped unicode fixes 394 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 --- src/plugins/network/RequestDetails.js | 12 ++++++++---- src/plugins/network/index.js | 5 ++++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/plugins/network/RequestDetails.js b/src/plugins/network/RequestDetails.js index f40dc6cc3..5c3278960 100644 --- a/src/plugins/network/RequestDetails.js +++ b/src/plugins/network/RequestDetails.js @@ -62,11 +62,15 @@ function decodeBody(container: Request | Response): string { if (!container.data) { return ''; } - const b64Decoded = decodeURIComponent(escape(atob(container.data))); + const b64Decoded = atob(container.data); + const body = + getHeaderValue(container.headers, 'Content-Encoding') === 'gzip' + ? decompress(b64Decoded) + : b64Decoded; - return 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 { diff --git a/src/plugins/network/index.js b/src/plugins/network/index.js index bd90c2478..7a8413573 100644 --- a/src/plugins/network/index.js +++ b/src/plugins/network/index.js @@ -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; }