File tree 1 file changed +12
-12
lines changed
src/Nethermind/Nethermind.Runner/scripts
1 file changed +12
-12
lines changed Original file line number Diff line number Diff line change @@ -81,19 +81,19 @@ export function parseExtraData(extraData: string | null | undefined): string {
81
81
// Convert hex -> bytes
82
82
const bytes = hexStringToUint8Array ( hex ) ;
83
83
84
- // Use the "toCleanUtf8String" logic
85
- const data = toCleanUtf8String ( bytes ) ;
86
-
87
- // The C# snippet's comment says:
88
- // "If the cleaned text is less than half length of input size, output it as hex, else output the text."
89
- // The original code in the snippet has a minor mismatch in the condition, but we’ll follow the comment:
90
- if ( data . length > ( bytes . length / 2 ) ) {
91
- // It's "mostly" valid text
92
- return data ;
93
- } else {
94
- // It's "mostly" not decodable text => show hex
84
+ // Decode to UTF-8
85
+ let decoder = new TextDecoder ( 'utf-8' , { fatal : false } ) ;
86
+ let decoded = decoder . decode ( bytes ) ;
87
+
88
+ // Count the number of control characters
89
+ let controlCount = decoded . split ( '' ) . filter ( c => isControlCharacter ( c . charCodeAt ( 0 ) ) ) . length ;
90
+
91
+ // Return the original hex string if there are too many control characters
92
+ if ( controlCount >= decoded . length / 2 ) {
95
93
return `0x${ hex } ` ;
96
- }
94
+
95
+ // Return the decoded string
96
+ return decoded ;
97
97
}
98
98
99
99
/**
You can’t perform that action at this time.
0 commit comments