From: Jakub Narebski <jnareb@gmail.com>
To: Anders Waldenborg <anders@0x63.nu>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] gitweb: Fix chop_str not to cut in middle of utf8 multibyte chars.
Date: Tue, 20 May 2008 15:19:01 -0700 (PDT) [thread overview]
Message-ID: <m3lk244o16.fsf@localhost.localdomain> (raw)
In-Reply-To: <g0vdse$rj6$1@ger.gmane.org>
Anders Waldenborg <anders@0x63.nu> writes:
> 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.
Thanks a lot. This is certainly a good thing, although I think that
the proper solution (but which would need much more work) would be to
ensure that all information is stored in Perl internal form, and not
only ensured on output.
I would change title of this commit to be more descriptive what this
commit does; or rather make current subject the first sentence of
commit summary, have something like the following for commit message:
gitweb: Convert string to Perl 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.
> Signed-off-by: Anders Waldenborg <anders@0x63.nu>
> ---
> 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.
--
Jakub Narebski
Poland
ShadeHawk on #git
next prev parent reply other threads:[~2008-05-20 22:20 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-05-20 20:55 [PATCH] gitweb: Fix chop_str not to cut in middle of utf8 multibyte chars Anders Waldenborg
2008-05-20 22:19 ` Jakub Narebski [this message]
2008-05-21 7:27 ` Junio C Hamano
2008-05-21 7:45 ` Anders Waldenborg
2008-05-24 13:34 ` Jakub Narebski
2008-05-21 11:44 ` [PATCH] gitweb: Convert string to internal form before chopping in chop_str Anders Waldenborg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m3lk244o16.fsf@localhost.localdomain \
--to=jnareb@gmail.com \
--cc=anders@0x63.nu \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).