Skip to contentSkip to conversation

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

PATCH New zzs 3 participants 5 messages Jun 15, 2016

lore
Share & tools
lore

zzs

author
#0 lore raw

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
index dab89f2..48def38 100755
@@ -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
#1 lore raw

Hi,

Quoted 12 lines · zzs
gitweb/gitweb.perl +1 -1
index dab89f2..48def38 100755
@@ -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

#2 lore raw
Quoted 18 lines · Ramkumar Ramachandra
Quoted 12 lines · zzs
gitweb/gitweb.perl +1 -1
index dab89f2..48def38 100755
@@ -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
#3 lore raw

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

author
#4 lore raw

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
index dab89f2..48def38 100755
@@ -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