]> Lady’s Gitweb - Gitweb/commitdiff
gitweb: Convert string to internal form before chopping in chop_str
authorAnders Waldenborg <redacted>
Wed, 21 May 2008 11:44:43 +0000 (13:44 +0200)
committerLady <redacted>
Mon, 6 Apr 2026 04:07:33 +0000 (00:07 -0400)
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 <redacted>
Signed-off-by: Junio C Hamano <redacted>
gitweb.perl

index 986c9ed2ec0852807528cbb604d281cf07fcbd31119b9844e64311c1bfa89b01..d3950f53c13812ef0cd8a4bfdc7630ce33a87fff13b2980caa9f3080ea2c5d55 100755 (executable)
@@ -867,6 +867,10 @@ sub chop_str {
        my $add_len = shift || 10;
        my $where = shift || 'right'; # 'left' | 'center' | 'right'
 
        my $add_len = shift || 10;
        my $where = shift || 'right'; # 'left' | 'center' | 'right'
 
+       # Make sure perl knows it is utf8 encoded so we don't
+       # cut in the middle of a utf8 multibyte char.
+       $str = to_utf8($str);
+
        # allow only $len chars, but don't cut a word if it would fit in $add_len
        # if it doesn't fit, cut it if it's still longer than the dots we would add
        # remove chopped character entities entirely
        # allow only $len chars, but don't cut a word if it would fit in $add_len
        # if it doesn't fit, cut it if it's still longer than the dots we would add
        # remove chopped character entities entirely
This page took 0.244776 seconds and 4 git commands to generate.