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

5 messages from 2011-08-04 to 2011-08-04. Participants: zzs, Ramkumar Ramachandra, Jakub Narębski.
Thread: https://gitlist.dev/t/28019

## zzs, 2011-08-04 05:31

Subject: gitweb highligh generate illegal char when the content had utf-8 chars
Message-ID: <20110804053123.GA13198@greatfirst.com>
URL: https://gitlist.dev/e/20110804053123.GA13198%40greatfirst.com

```
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, 2011-08-04 09:11

Subject: Re: gitweb highligh generate illegal char when the content had utf-8 chars
Message-ID: <CALkWK0kURz_Rax-JOPT2sW1x4VrqWk=KDjUzzw4apacDo1UTyg@mail.gmail.com>
URL: https://gitlist.dev/e/CALkWK0kURz_Rax-JOPT2sW1x4VrqWk%3DKDjUzzw4apacDo1UTyg%40mail.gmail.com
In-Reply-To: <20110804053123.GA13198@greatfirst.com>

```
Hi,

zzs writes:
> 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, 2011-08-04 09:39

Subject: Re: gitweb highligh generate illegal char when the content had utf-8 chars
Message-ID: <CANQwDwcR5sS3-m6SifQbjU1VoS5bxRRGJNZZj0U+zp=zsoGbLA@mail.gmail.com>
URL: https://gitlist.dev/e/CANQwDwcR5sS3-m6SifQbjU1VoS5bxRRGJNZZj0U%2Bzp%3DzsoGbLA%40mail.gmail.com
In-Reply-To: <CALkWK0kURz_Rax-JOPT2sW1x4VrqWk=KDjUzzw4apacDo1UTyg@mail.gmail.com>

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

>> 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, 2011-08-04 10:05

Subject: Re: gitweb highligh generate illegal char when the content had utf-8 chars
Message-ID: <CALkWK0kOTXyevPy0Ys+pWwGjr2NSo3+ifhWuPVU+=FL=LC=J7A@mail.gmail.com>
URL: https://gitlist.dev/e/CALkWK0kOTXyevPy0Ys%2BpWwGjr2NSo3%2BifhWuPVU%2B%3DFL%3DLC%3DJ7A%40mail.gmail.com
In-Reply-To: <CANQwDwcR5sS3-m6SifQbjU1VoS5bxRRGJNZZj0U+zp=zsoGbLA@mail.gmail.com>

```
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, 2011-08-04 15:52

Subject: [PATCH] fix gitweb syntax highlight utf-8 encode bug
Message-ID: <1312473175-28195-1-git-send-email-zzs213@126.com>
URL: https://gitlist.dev/e/1312473175-28195-1-git-send-email-zzs213%40126.com
In-Reply-To: <CALkWK0kOTXyevPy0Ys+pWwGjr2NSo3+ifhWuPVU+=FL=LC=J7A@mail.gmail.com>

```
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

```
