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>
This commit is contained in:
parent
3273ebc759
commit
2dcb5e1ac8
@ -2740,6 +2740,15 @@ sub get_file_owner {
|
|||||||
return to_utf8($owner);
|
return to_utf8($owner);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# assume that file exists
|
||||||
|
sub insert_file {
|
||||||
|
my $filename = shift;
|
||||||
|
|
||||||
|
open my $fd, '<', $filename;
|
||||||
|
print map(to_utf8, <$fd>);
|
||||||
|
close $fd;
|
||||||
|
}
|
||||||
|
|
||||||
## ......................................................................
|
## ......................................................................
|
||||||
## mimetype related functions
|
## mimetype related functions
|
||||||
|
|
||||||
@ -2928,9 +2937,7 @@ EOF
|
|||||||
"<body>\n";
|
"<body>\n";
|
||||||
|
|
||||||
if (-f $site_header) {
|
if (-f $site_header) {
|
||||||
open (my $fd, $site_header);
|
insert_file($site_header);
|
||||||
print <$fd>;
|
|
||||||
close $fd;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
print "<div class=\"page_header\">\n" .
|
print "<div class=\"page_header\">\n" .
|
||||||
@ -3017,9 +3024,7 @@ sub git_footer_html {
|
|||||||
print "</div>\n"; # class="page_footer"
|
print "</div>\n"; # class="page_footer"
|
||||||
|
|
||||||
if (-f $site_footer) {
|
if (-f $site_footer) {
|
||||||
open (my $fd, $site_footer);
|
insert_file($site_footer);
|
||||||
print <$fd>;
|
|
||||||
close $fd;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
print "</body>\n" .
|
print "</body>\n" .
|
||||||
@ -4358,9 +4363,7 @@ sub git_project_list {
|
|||||||
git_header_html();
|
git_header_html();
|
||||||
if (-f $home_text) {
|
if (-f $home_text) {
|
||||||
print "<div class=\"index_include\">\n";
|
print "<div class=\"index_include\">\n";
|
||||||
open (my $fd, $home_text);
|
insert_file($home_text);
|
||||||
print <$fd>;
|
|
||||||
close $fd;
|
|
||||||
print "</div>\n";
|
print "</div>\n";
|
||||||
}
|
}
|
||||||
print $cgi->startform(-method => "get") .
|
print $cgi->startform(-method => "get") .
|
||||||
@ -4472,13 +4475,10 @@ sub git_summary {
|
|||||||
print "</table>\n";
|
print "</table>\n";
|
||||||
|
|
||||||
if (-s "$projectroot/$project/README.html") {
|
if (-s "$projectroot/$project/README.html") {
|
||||||
if (open my $fd, "$projectroot/$project/README.html") {
|
print "<div class=\"title\">readme</div>\n" .
|
||||||
print "<div class=\"title\">readme</div>\n" .
|
"<div class=\"readme\">\n";
|
||||||
"<div class=\"readme\">\n";
|
insert_file("$projectroot/$project/README.html");
|
||||||
print $_ while (<$fd>);
|
print "\n</div>\n"; # class="readme"
|
||||||
print "\n</div>\n"; # class="readme"
|
|
||||||
close $fd;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# we need to request one more than 16 (0..15) to check if
|
# we need to request one more than 16 (0..15) to check if
|
||||||
|
Loading…
Reference in New Issue
Block a user