Skip to content

Commit 2dcb5e1

Browse files
jnarebgitster
authored andcommitted
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>
1 parent 3273ebc commit 2dcb5e1

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

gitweb/gitweb.perl

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2740,6 +2740,15 @@ sub get_file_owner {
27402740
return to_utf8($owner);
27412741
}
27422742

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+
27432752
## ......................................................................
27442753
## mimetype related functions
27452754

@@ -2928,9 +2937,7 @@ sub git_header_html {
29282937
"<body>\n";
29292938

29302939
if (-f $site_header) {
2931-
open (my $fd, $site_header);
2932-
print <$fd>;
2933-
close $fd;
2940+
insert_file($site_header);
29342941
}
29352942

29362943
print "<div class=\"page_header\">\n" .
@@ -3017,9 +3024,7 @@ sub git_footer_html {
30173024
print "</div>\n"; # class="page_footer"
30183025

30193026
if (-f $site_footer) {
3020-
open (my $fd, $site_footer);
3021-
print <$fd>;
3022-
close $fd;
3027+
insert_file($site_footer);
30233028
}
30243029

30253030
print "</body>\n" .
@@ -4358,9 +4363,7 @@ sub git_project_list {
43584363
git_header_html();
43594364
if (-f $home_text) {
43604365
print "<div class=\"index_include\">\n";
4361-
open (my $fd, $home_text);
4362-
print <$fd>;
4363-
close $fd;
4366+
insert_file($home_text);
43644367
print "</div>\n";
43654368
}
43664369
print $cgi->startform(-method => "get") .
@@ -4472,13 +4475,10 @@ sub git_summary {
44724475
print "</table>\n";
44734476

44744477
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"
44824482
}
44834483

44844484
# we need to request one more than 16 (0..15) to check if

0 commit comments

Comments
 (0)