Subject: [PATCH] gitweb: Fix bug in insert_file() subroutine

From: Jakub Narebski <[email-masked]>
Date: Mon, 08 Dec 2008 14:13:21 +0100

In insert_file() subroutine (which is used to insert HTML fragments as
custom header, footer, hometext (for projects list view), and per
project README.html (for summary view)) we used:

     map(to_utf8, <$fd>);

This doesn't work, and other form has to be used:

     map { to_utf8($_) } <$fd>;

Now with test for t9600 added, for $GIT_DIR/README.html.

Signed-off-by: Jakub Narebski <[email-masked]>
---
Junio C Hamano wrote:
> Jakub Narebski <[email-masked]> writes:
>> 
>> With "close $fd" removed the patch is correct (and patches t9500*).
> 
> Yeah, it passes that test here, too.  Let's unleash it to 'master' and in
> an unlikely case where it still has bugs we know which commit to revert
> ;-).

I'm extremely sorry about that, but it still had bugs. I thought
I could use "map EXPR,LIST" form instead of "map BLOCK LIST" here,
i.e. "map(to_utf8, <$fd>)" instead of "map {to_utf8($_)} <$fd>;"
in original patch by Tatsuki Sugiura.

Just in case I have added check for this in t9500 gitweb test.

Once again, I'm very sorry for my buggy patches...

 gitweb/gitweb.perl                     |    2 +-
 t/t9500-gitweb-standalone-no-errors.sh |   10 ++++++++++
 2 files changed, 11 insertions(+), 1 deletions(-)

diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 9517392..6eb370d 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -2764,7 +2764,7 @@ sub insert_file {
 	my $filename = shift;
 
 	open my $fd, '<', $filename;
-	print map(to_utf8, <$fd>);
+	print map { to_utf8($_) } <$fd>;
 	close $fd;
 }
 
diff --git a/t/t9500-gitweb-standalone-no-errors.sh b/t/t9500-gitweb-standalone-no-errors.sh
index 64c4cce..43cd6ee 100755
--- a/t/t9500-gitweb-standalone-no-errors.sh
+++ b/t/t9500-gitweb-standalone-no-errors.sh
@@ -673,4 +673,14 @@ test_expect_success \
 	 gitweb_run "p=.git;a=tree"'
 test_debug 'cat gitweb.log'
 
+# ----------------------------------------------------------------------
+# non-ASCII in README.html
+
+test_expect_success \
+	'README.html with non-ASCII characters (utf-8)' \
+	'echo "<b>UTF-8 example:</b><br />" > .git/README.html &&
+	 cat "$TEST_DIRECTORY"/t3900/1-UTF-8.txt >> .git/README.html &&
+	 gitweb_run "p=.git;a=summary"'
+test_debug 'cat gitweb.log'
+
 test_done

-- 
Stacked GIT 0.14.3
git version 1.6.0.4