@@ -175,19 +175,26 @@ impl DataType {
175175 }
176176 DataType :: String => {
177177 if let Some ( nul_idx) = bytes. iter ( ) . position ( |& c| c == b'\0' ) {
178- let str_bytes = & bytes[ ..nul_idx] ;
178+ let ascii_str_bytes = & bytes[ ..nul_idx] ;
179179 // Special case to display (ASCII) as the label for ASCII-only strings.
180- let ( cow, _, had_errors) = encoding_rs:: UTF_8 . decode ( str_bytes ) ;
180+ let ( cow, _, had_errors) = encoding_rs:: UTF_8 . decode ( ascii_str_bytes ) ;
181181 if !had_errors && cow. is_ascii ( ) {
182182 let string = format ! ( "{cow}" ) ;
183183 let copy_string = escape_special_ascii_characters ( string. clone ( ) ) ;
184184 strs. push ( ( string, Some ( "ASCII" . into ( ) ) , Some ( copy_string) ) ) ;
185185 }
186+
186187 for ( encoding, encoding_name) in SUPPORTED_ENCODINGS {
187- let ( cow, _, had_errors) = encoding. decode ( str_bytes ) ;
188+ let ( cow, _, had_errors) = encoding. decode ( & bytes ) ;
188189 // Avoid showing ASCII-only strings more than once if the encoding is ASCII-compatible.
189190 if !had_errors && ( !encoding. is_ascii_compatible ( ) || !cow. is_ascii ( ) ) {
190- let string = format ! ( "{cow}" ) ;
191+ let mut string = format ! ( "{cow}" ) ;
192+
193+ // Inline loop to strip all trailing "\0"
194+ while let Some ( stripped) = string. strip_suffix ( '\0' ) {
195+ string = stripped. to_string ( ) ;
196+ }
197+
191198 let copy_string = escape_special_ascii_characters ( string. clone ( ) ) ;
192199 strs. push ( ( string, Some ( encoding_name. into ( ) ) , Some ( copy_string) ) ) ;
193200 }
0 commit comments