git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Jakub Narebski <jnareb@gmail.com>
Date
Dec 8, 2008, 13:13 UTC
Message-ID
<20081208130905.15803.83149.stgit@localhost.localdomain>
In-Reply-To
<7vfxl5c66h.fsf@gitster.siamese.dyndns.org>

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 <jnareb@gmail.com>
---
Junio C Hamano wrote:
Show 7 quoted lines
> Jakub Narebski <jnareb@gmail.com> 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
Previous: Junio C HamanoNext: Junio C Hamano
Message 8 of 9 in “gitweb: fix encode handling for site_{header,footer}”
  1. gitweb: fix encode handling for site_{header,footer}Tatsuki Sugiura, Nov 17, 2008
  2. Junio C HamanoNov 17, 2008
  3. Jakub NarebskiNov 17, 2008
  4. gitweb: Fix handling of non-ASCII characters in inserted HTML filesJakub Narebski, Dec 1, 2008
  5. Junio C HamanoDec 3, 2008
  6. Jakub NarebskiDec 3, 2008
  7. Junio C HamanoDec 3, 2008
  8. gitweb: Fix bug in insert_file() subroutineJakub Narebski, Dec 8, 2008
  9. Junio C HamanoDec 8, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.