@matheusbsbs / matheus-bagliano / commits / 2dcb5e1ac8
Fork 0

gitweb: Fix handling of non-ASCII characters in inserted HTML files

Use new insert_file() subroutine to insert HTML chunks from external files: $site_header, $home_text (by default indextext.html), $site_footer, and $projectroot/$project/REAME.html. All non-ASCII chars of those files will be broken by Perl IO layer without decoding to utf8, so insert_file() does to_utf8() on each printed line; alternate solution would be to open those files with "binmode $fh, ':utf8'", or even all files with "use open qw(:std :utf8)". Note that inserting README.html lost one of checks for simplicity. Noticed-by: Tatsuki Sugiura <sugi@nemui.org> Signed-off-by: Jakub Narebski <jnareb@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jakub Narebski committed Dec 1, 2008 at 19:01 UTC 2dcb5e1ac87330b20962af9199a345eb378d3705
1 file changed +16 -16
gitweb/gitweb.perl
+16 -16
@@ -2740,6 +2740,15 @@ sub get_file_owner {
2740 return to_utf8($owner);
2741 }
2742
2743 +# assume that file exists
2744 +sub insert_file {
2745 + my $filename = shift;
2746 +
2747 + open my $fd, '<', $filename;
2748 + print map(to_utf8, <$fd>);
2749 + close $fd;
2750 +}
2751 +
2752 ## ......................................................................
2753 ## mimetype related functions
2754
@@ -2928,9 +2937,7 @@ EOF
2937 "<body>\n";
2938
2939 if (-f $site_header) {
2931 - open (my $fd, $site_header);
2932 - print <$fd>;
2933 - close $fd;
2940 + insert_file($site_header);
2941 }
2942
2943 print "<div class=\"page_header\">\n" .
@@ -3017,9 +3024,7 @@ sub git_footer_html {
3024 print "</div>\n"; # class="page_footer"
3025
3026 if (-f $site_footer) {
3020 - open (my $fd, $site_footer);
3021 - print <$fd>;
3022 - close $fd;
3027 + insert_file($site_footer);
3028 }
3029
3030 print "</body>\n" .
@@ -4358,9 +4363,7 @@ sub git_project_list {
4363 git_header_html();
4364 if (-f $home_text) {
4365 print "<div class=\"index_include\">\n";
4361 - open (my $fd, $home_text);
4362 - print <$fd>;
4363 - close $fd;
4366 + insert_file($home_text);
4367 print "</div>\n";
4368 }
4369 print $cgi->startform(-method => "get") .
@@ -4472,13 +4475,10 @@ sub git_summary {
4475 print "</table>\n";
4476
4477 if (-s "$projectroot/$project/README.html") {
4475 - if (open my $fd, "$projectroot/$project/README.html") {
4476 - print "<div class=\"title\">readme</div>\n" .
4477 - "<div class=\"readme\">\n";
4478 - print $_ while (<$fd>);
4479 - print "\n</div>\n"; # class="readme"
4480 - close $fd;
4481 - }
4478 + print "<div class=\"title\">readme</div>\n" .
4479 + "<div class=\"readme\">\n";
4480 + insert_file("$projectroot/$project/README.html");
4481 + print "\n</div>\n"; # class="readme"
4482 }
4483
4484 # we need to request one more than 16 (0..15) to check if