From 2f77d62242bcf0e58212aaeb9c5cc24955e76a7e Mon Sep 17 00:00:00 2001 From: Josep M Sobrepere Date: Tue, 19 Nov 2024 15:06:18 +0100 Subject: [PATCH] improve BinaryInput --- src/components/BinaryInput.tsx | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/components/BinaryInput.tsx b/src/components/BinaryInput.tsx index fb910cf..4a6337e 100644 --- a/src/components/BinaryInput.tsx +++ b/src/components/BinaryInput.tsx @@ -162,13 +162,7 @@ const textDecoder = new TextDecoder("utf-8", { fatal: true }) export const bytesToString = (value: Binary) => { try { const bytes = value.asBytes() - const nullPos = bytes.indexOf(0) - // if there's a null character (except at the end of the text) we want hex - if ( - bytes.length === 0 || - (nullPos !== -1 && (bytes.length === 1 || nullPos !== bytes.length - 1)) - ) - throw null + if (bytes.slice(0, 5).every((b) => b < 32)) throw null return textDecoder.decode(bytes) } catch (_) { return value.asHex()