@@ -721,7 +721,7 @@ impl EmitterWriter {
721721 }
722722
723723 let source_string = match file. get_line ( line. line_index - 1 ) {
724- Some ( s) => replace_tabs ( & * s) ,
724+ Some ( s) => normalize_whitespace ( & * s) ,
725725 None => return Vec :: new ( ) ,
726726 } ;
727727
@@ -1272,7 +1272,7 @@ impl EmitterWriter {
12721272 buffer. append ( 0 , ": " , header_style) ;
12731273 }
12741274 for & ( ref text, _) in msg. iter ( ) {
1275- buffer. append ( 0 , & replace_tabs ( text) , header_style) ;
1275+ buffer. append ( 0 , & normalize_whitespace ( text) , header_style) ;
12761276 }
12771277 }
12781278
@@ -1526,7 +1526,7 @@ impl EmitterWriter {
15261526
15271527 self . draw_line (
15281528 & mut buffer,
1529- & replace_tabs ( & unannotated_line) ,
1529+ & normalize_whitespace ( & unannotated_line) ,
15301530 annotated_file. lines [ line_idx + 1 ] . line_index - 1 ,
15311531 last_buffer_line_num,
15321532 width_offset,
@@ -1648,7 +1648,7 @@ impl EmitterWriter {
16481648 buffer. puts (
16491649 row_num - 1 ,
16501650 max_line_num_len + 3 ,
1651- & replace_tabs (
1651+ & normalize_whitespace (
16521652 & * file_lines
16531653 . file
16541654 . get_line ( file_lines. lines [ line_pos] . line_index )
@@ -1674,7 +1674,7 @@ impl EmitterWriter {
16741674 }
16751675
16761676 // print the suggestion
1677- buffer. append ( row_num, & replace_tabs ( line) , Style :: NoStyle ) ;
1677+ buffer. append ( row_num, & normalize_whitespace ( line) , Style :: NoStyle ) ;
16781678
16791679 // Colorize addition/replacements with green.
16801680 for & SubstitutionHighlight { start, end } in highlight_parts {
@@ -2054,8 +2054,17 @@ fn num_decimal_digits(num: usize) -> usize {
20542054 MAX_DIGITS
20552055}
20562056
2057- fn replace_tabs ( str : & str ) -> String {
2058- str. replace ( '\t' , " " )
2057+ const REPLACEMENTS : & [ ( char , & str ) ] = & [
2058+ ( '\t' , " " ) ,
2059+ ( '\u{200D}' , "" ) , // Replace ZWJ with nothing for consistent terminal output of grapheme clusters.
2060+ ] ;
2061+
2062+ fn normalize_whitespace ( str : & str ) -> String {
2063+ let mut output = str. to_string ( ) ;
2064+ for ( c, replacement) in REPLACEMENTS {
2065+ output = output. replace ( * c, replacement) ;
2066+ }
2067+ output
20592068}
20602069
20612070fn draw_col_separator ( buffer : & mut StyledBuffer , line : usize , col : usize ) {
0 commit comments