git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jakub Narebski <jnareb@gmail.com>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>,
	Tatsuki Sugiura <sugi@nemui.org>, Gerrit Pape <pape@smarden.org>,
	Recai Oktas <roktas@debian.org>
Subject: [PATCH] gitweb: Fix handling of non-ASCII characters in inserted HTML files
Date: Mon, 01 Dec 2008 19:01:42 +0100	[thread overview]
Message-ID: <20081201175741.11133.82393.stgit@localhost.localdomain> (raw)
In-Reply-To: <200811171140.45884.jnareb@gmail.com>

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>
---
This is more complete solution that the one provided by Tatsuki Sugiura
in original patch

  [PATCH] gitweb: fix encode handling for site_{header,footer}
  Msg-Id: <87vdumbxgc.wl@vaj-k-334-sugi.local.valinux.co.jp>
  http://thread.gmane.org/gmane.comp.version-control.git/101199

but it is in principle the same solution.

I think this one as it is a bugfix should go in git 1.6.1

 gitweb/gitweb.perl |   33 +++++++++++++++++----------------
 1 files changed, 17 insertions(+), 16 deletions(-)

diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 933e137..82262a3 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -2740,6 +2740,15 @@ sub get_file_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
 
@@ -2928,9 +2937,7 @@ EOF
 	      "<body>\n";
 
 	if (-f $site_header) {
-		open (my $fd, $site_header);
-		print <$fd>;
-		close $fd;
+		insert_file($site_header);
 	}
 
 	print "<div class=\"page_header\">\n" .
@@ -3017,9 +3024,7 @@ sub git_footer_html {
 	print "</div>\n"; # class="page_footer"
 
 	if (-f $site_footer) {
-		open (my $fd, $site_footer);
-		print <$fd>;
-		close $fd;
+		insert_file($site_footer);
 	}
 
 	print "</body>\n" .
@@ -4358,9 +4363,7 @@ sub git_project_list {
 	git_header_html();
 	if (-f $home_text) {
 		print "<div class=\"index_include\">\n";
-		open (my $fd, $home_text);
-		print <$fd>;
-		close $fd;
+		insert_file($home_text);
 		print "</div>\n";
 	}
 	print $cgi->startform(-method => "get") .
@@ -4472,13 +4475,11 @@ sub git_summary {
 	print "</table>\n";
 
 	if (-s "$projectroot/$project/README.html") {
-		if (open my $fd, "$projectroot/$project/README.html") {
-			print "<div class=\"title\">readme</div>\n" .
-			      "<div class=\"readme\">\n";
-			print $_ while (<$fd>);
-			print "\n</div>\n"; # class="readme"
-			close $fd;
-		}
+		print "<div class=\"title\">readme</div>\n" .
+		      "<div class=\"readme\">\n";
+		insert_file("$projectroot/$project/README.html");
+		print "\n</div>\n"; # class="readme"
+		close $fd;
 	}
 
 	# we need to request one more than 16 (0..15) to check if

  reply	other threads:[~2008-12-01 18:03 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-11-17  7:53 [PATCH] gitweb: fix encode handling for site_{header,footer} Tatsuki Sugiura
2008-11-17 10:28 ` Junio C Hamano
2008-11-17 10:40   ` Jakub Narebski
2008-12-01 18:01     ` Jakub Narebski [this message]
2008-12-03  3:55       ` [PATCH] gitweb: Fix handling of non-ASCII characters in inserted HTML files Junio C Hamano
2008-12-03 10:21         ` Jakub Narebski
2008-12-03 21:14           ` Junio C Hamano
2008-12-08 13:13             ` [PATCH] gitweb: Fix bug in insert_file() subroutine Jakub Narebski
2008-12-08 17:05               ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20081201175741.11133.82393.stgit@localhost.localdomain \
    --to=jnareb@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=pape@smarden.org \
    --cc=roktas@debian.org \
    --cc=sugi@nemui.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).