gitweb highligh generate illegal char when the content had utf-8 chars
When my C file had some utf-8 comments, gitweb highlight generate illegal chars.
So I hacked gitweb.cgi, like this:
---------------------------
gitweb/gitweb.perl +1 -1
@@ -6465,7 +6465,7 @@ sub git_blob { $nr++; $line = untabify($line); printf qq!<div class="pre"><a id="l%i" href="%s#l%i" class="linenr">%4i</a> %s</div>\n!, - $nr, esc_attr(href(-replay => 1)), $nr, $nr, $syntax ? $line : esc_html($line, -nbsp=>1); + $nr, esc_attr(href(-replay => 1)), $nr, $nr, $syntax ? to_utf8($line) : esc_html($line, -nbsp=>1); } } close $fd
---------------------------
And it works.
But I wonder is this the rigtht solution.
Anybody help me?
Signature · 2 lines
Best Regards zzs
Hi,
Quoted 12 lines · zzs
gitweb/gitweb.perl +1
-1@@ -6465,7 +6465,7 @@ sub git_blob { $nr++; $line = untabify($line); printf qq!<div class="pre"><a id="l%i" href="%s#l%i" class="linenr">%4i</a> %s</div>\n!, - $nr, esc_attr(href(-replay => 1)), $nr, $nr, $syntax ? $line : esc_html($line, -nbsp=>1); + $nr, esc_attr(href(-replay => 1)), $nr, $nr, $syntax ? to_utf8($line) : esc_html($line, -nbsp=>1); } }
Quoted 1 line
close $fd
Looks sane, but I don't know enough about Gitweb to comment. +CC: Jakub, who can probably say more.
Thanks.
-- Ram
Quoted 18 lines · Ramkumar Ramachandra
Quoted 12 lines · zzs
gitweb/gitweb.perl +1
-1@@ -6465,7 +6465,7 @@ sub git_blob { $nr++; $line = untabify($line); printf qq!<div class="pre"><a id="l%i" href="%s#l%i" class="linenr">%4i</a> %s</div>\n!, - $nr, esc_attr(href(-replay => 1)), $nr, $nr, $syntax ? $line : esc_html($line, -nbsp=>1); + $nr, esc_attr(href(-replay => 1)), $nr, $nr, $syntax ? to_utf8($line) : esc_html($line, -nbsp=>1); } }Quoted 1 line
close $fd
Looks sane, but I don't know enough about Gitweb to comment. +CC: Jakub, who can probably say more.
This looks correct.
Signature · 1 line
Jakub Narebski
Hi,
Quoted 1 line · Jakub Narębski
This looks correct.
Thanks Jakub.
Quoted 3 lines
Quoted 3 lines
gitweb/gitweb.perl
Quoted 2 lines · zzs
gitweb/gitweb.perl +0
-0
Please submit a nicely formatted patch with proper signoff so that we can consider this for inclusion. Refer to Documentation/SubmittingPatches for more details.
Thanks.
-- Ram
PATCH 1/1 fix gitweb syntax highlight utf-8 encode bug
From: 张忠山 <[email protected]>
--- gitweb/gitweb.perl | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
gitweb/gitweb.perl +1 -1
@@ -6465,7 +6465,7 @@ sub git_blob { $nr++; $line = untabify($line); printf qq!<div class="pre"><a id="l%i" href="%s#l%i" class="linenr">%4i</a> %s</div>\n!, - $nr, esc_attr(href(-replay => 1)), $nr, $nr, $syntax ? $line : esc_html($line, -nbsp=>1); + $nr, esc_attr(href(-replay => 1)), $nr, $nr, $syntax ? to_utf8($line) : esc_html($line, -nbsp=>1); } } close $fd
Signature · 1 line
1.7.4.4