From cbff1837c13523ec456c284c86e45567e4d794b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=2E=20Mert=20Y=C4=B1ld=C4=B1ran?= Date: Mon, 31 Jan 2022 17:58:38 +0300 Subject: [PATCH] Fix protobuf prettify logic (#732) --- ui/src/components/EntryDetailed/EntrySections.tsx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/ui/src/components/EntryDetailed/EntrySections.tsx b/ui/src/components/EntryDetailed/EntrySections.tsx index e66b9810d..b5127fa17 100644 --- a/ui/src/components/EntryDetailed/EntrySections.tsx +++ b/ui/src/components/EntryDetailed/EntrySections.tsx @@ -137,12 +137,12 @@ export const EntryBodySection: React.FC = ({ const chunk = body.slice(0, MAXIMUM_BYTES_TO_FORMAT); const bodyBuf = isBase64Encoding ? atob(chunk) : chunk; - if (!isPretty) return bodyBuf; - try { if (jsonLikeFormats.some(format => contentType?.indexOf(format) > -1)) { + if (!isPretty) return bodyBuf; return jsonBeautify(JSON.parse(bodyBuf), null, 2, 80); } else if (xmlLikeFormats.some(format => contentType?.indexOf(format) > -1)) { + if (!isPretty) return bodyBuf; return xmlBeautify(bodyBuf, { indentation: ' ', filter: (node) => node.type !== 'Comment', @@ -152,7 +152,9 @@ export const EntryBodySection: React.FC = ({ } else if (protobufFormats.some(format => contentType?.indexOf(format) > -1)) { // Replace all non printable characters (ASCII) const protobufDecoder = new ProtobufDecoder(bodyBuf, true); - return jsonBeautify(protobufDecoder.decode().toSimple(), null, 2, 80); + const protobufDecoded = protobufDecoder.decode().toSimple(); + if (!isPretty) return JSON.stringify(protobufDecoded); + return jsonBeautify(protobufDecoded, null, 2, 80); } } catch (error) { console.error(error);