threads / discuss / 28019

gitweb highligh generate illegal char when the content had utf-8 chars

Subject: gitweb highligh generate illegal char when the content had utf-8 chars

## tl;dr

5 messages between Aug 4, 2011 and Aug 4, 2011.

replies: 4people: 3as markdown or json

zzs· Aug 4, 2011, 05:31 UTC · lore

When my C file had some utf-8 comments, gitweb highlight generate illegal chars.

So I hacked gitweb.cgi, like this:
---------------------------
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index dab89f2..48def38 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -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?
-- 
Best Regards
zzs
Ramkumar Ramachandra· Aug 4, 2011, 09:11 UTC · re: zzs · lore

Re: gitweb highligh generate illegal char when the content had utf-8 chars

Hi,
zzs writes:
Show 13 quoted lines
> diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
> index dab89f2..48def38 100755
> --- a/gitweb/gitweb.perl
> +++ b/gitweb/gitweb.perl
> @@ -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

Looks sane, but I don't know enough about Gitweb to comment. +CC: Jakub, who can probably say more.

Thanks.
-- Ram
Jakub Narębski· Aug 4, 2011, 09:39 UTC · re: Ramkumar Ramachandra · lore

Re: gitweb highligh generate illegal char when the content had utf-8 chars

On Thu, Aug 4, 2011 at 11:11 AM, Ramkumar Ramachandra <artagnon@gmail.com> wrote:

> zzs writes:
Show 16 quoted lines
>> diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
>> index dab89f2..48def38 100755
>> --- a/gitweb/gitweb.perl
>> +++ b/gitweb/gitweb.perl
>> @@ -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
>
> Looks sane, but I don't know enough about Gitweb to comment.
> +CC: Jakub, who can probably say more.
This looks correct.
-- 
Jakub Narebski
Ramkumar Ramachandra· Aug 4, 2011, 10:05 UTC · re: Jakub Narębski · lore

Re: gitweb highligh generate illegal char when the content had utf-8 chars

Hi,
Jakub Narębski writes:
> This looks correct.
Thanks Jakub.
>> zzs writes:
>>> diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
>>> index dab89f2..48def38 100755

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
zzs· Aug 4, 2011, 15:52 UTC · re: Ramkumar Ramachandra · lore

[PATCH] fix gitweb syntax highlight utf-8 encode bug

From: 张忠山 <zzs213@126.com>
Signed-off-by: 张忠山 <zzs213@126.com>
---
 gitweb/gitweb.perl |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index dab89f2..48def38 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -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
-- 
1.7.4.4

← back to recent threads