summaryrefslogtreecommitdiff
path: root/gitweb/gitweb.perl
diff options
context:
space:
mode:
authorShin Kojima <shin@kojima.org>2016-05-03 13:00:51 (GMT)
committerJunio C Hamano <gitster@pobox.com>2016-05-03 18:32:31 (GMT)
commit029f37217c01fc6437357a30cd1b084b03ca872b (patch)
treea9216c3b89921eedf841ffed1b5eed26184969a5 /gitweb/gitweb.perl
parent765428699a5381f113d19974720bc91b5bfeaf1d (diff)
downloadgit-029f37217c01fc6437357a30cd1b084b03ca872b.zip
git-029f37217c01fc6437357a30cd1b084b03ca872b.tar.gz
git-029f37217c01fc6437357a30cd1b084b03ca872b.tar.bz2
gitweb: apply fallback encoding before highlight
Some multi-byte character encodings (such as Shift_JIS and GBK) have characters whose final bytes is an ASCII '\' (0x5c), and they will be displayed as funny-characters even if $fallback_encoding is correct. This is because `highlight` command always expects UTF-8 encoded strings from STDIN. $ echo 'my $v = "申";' | highlight --syntax perl | w3m -T text/html -dump my $v = "申"; $ echo 'my $v = "申";' | iconv -f UTF-8 -t Shift_JIS | highlight \ --syntax perl | iconv -f Shift_JIS -t UTF-8 | w3m -T text/html -dump iconv: (stdin):9:135: cannot convert my $v = " This patch prepare git blob objects to be encoded into UTF-8 before highlighting in the manner of `to_utf8` subroutine. Signed-off-by: Shin Kojima <shin@kojima.org> Reviewed-by: Jakub Narębski <jnareb@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'gitweb/gitweb.perl')
-rwxr-xr-xgitweb/gitweb.perl3
1 files changed, 3 insertions, 0 deletions
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 7a5b23a..17ff394 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -3935,6 +3935,9 @@ sub run_highlighter {
close $fd;
open $fd, quote_command(git_cmd(), "cat-file", "blob", $hash)." | ".
+ quote_command($^X, '-CO', '-MEncode=decode,FB_DEFAULT', '-pse',
+ '$_ = decode($fe, $_, FB_DEFAULT) if !utf8::decode($_);',
+ '--', "-fe=$fallback_encoding")." | ".
quote_command($highlight_bin).
" --replace-tabs=8 --fragment --syntax $syntax |"
or die_error(500, "Couldn't open file or run syntax highlighter");