Skip to content

Commit dee2775

Browse files
wandersgitster
authored andcommitted
gitweb: Convert string to internal form before chopping in chop_str
Fix chop_str not to cut in middle of utf8 multibyte chars. Without this fix at least author name in short log may cut in middle of a multibyte char. When the result comes to esc_html to_utf8 is called again, which doesn't find valid utf8 and decodes using $fallback_encoding making it even worse. This also have the nice side effect that it actually tries to show the first 10 _characters_, not the number of characters that happened to fit into 10 bytes. Signed-off-by: Anders Waldenborg <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1af8bca commit dee2775

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

gitweb/gitweb.perl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -866,6 +866,10 @@ sub chop_str {
866866
my $add_len = shift || 10;
867867
my $where = shift || 'right'; # 'left' | 'center' | 'right'
868868

869+
# Make sure perl knows it is utf8 encoded so we don't
870+
# cut in the middle of a utf8 multibyte char.
871+
$str = to_utf8($str);
872+
869873
# allow only $len chars, but don't cut a word if it would fit in $add_len
870874
# if it doesn't fit, cut it if it's still longer than the dots we would add
871875
# remove chopped character entities entirely

0 commit comments

Comments
 (0)