Jakub Narebski <jnareb@xxxxxxxxx> writes: > Anders Waldenborg <anders@xxxxxxx> writes: > ... > 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. > >> Signed-off-by: Anders Waldenborg <anders@xxxxxxx> >> --- >> gitweb/gitweb.perl | 4 ++++ >> 1 files changed, 4 insertions(+), 0 deletions(-) >> >> diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl >> index 2facf2d..8308e22 100755 >> --- a/gitweb/gitweb.perl >> +++ b/gitweb/gitweb.perl >> @@ -866,6 +866,10 @@ sub chop_str { >> 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); >> + > > I like the comment here. It explains the whys of code. > >> # 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 patch is whitespace damaged, by the way. I haven't followed the codepath but what do the callers do to the string returned from chop_str? Don't they assume the string hasn't been decoded (because the old implementation of chop_str did not do this to_utf8), and emit the result directly to the output because it also assumes the undecoded format is what the outside world wants? In other words, don't they now need to do different things because returned string has gone through the to_utf8() processing already? Maybe I am worrying too much, after getting burned by decode_utf/encode_utf data chains in another popular scripting language, and it is possible that with Perl you may not have to be so careful... -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html