gitweb: fix encode handling for site_{header,footer}
PATCH 1/1 gitweb: fix encode handling for site_{header,footer}
All non-ASCII chars of site_{header,footer} will be broken by perl IO layer without decoding to utf8.
Here is a fix to just call to_utf8 for inputs from these files.
--- gitweb/gitweb.perl | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
gitweb/gitweb.perl +2 -2
@@ -2929,7 +2929,7 @@ EOF if (-f $site_header) { open (my $fd, $site_header); - print <$fd>; + print map {to_utf8($_)} <$fd>; close $fd; }
@@ -3018,7 +3018,7 @@ sub git_footer_html { if (-f $site_footer) { open (my $fd, $site_footer); - print <$fd>; + print map {to_utf8($_)} <$fd>; close $fd; }
Signature · 1 line
1.5.6.5
Quoted 6 lines · Tatsuki Sugiura
All non-ASCII chars of site_{header,footer} will be broken by perl IO layer without decoding to utf8.
Here is a fix to just call
to_utf8for inputs from these files.Signed-off-by Tatsuki Sugiura <[email protected]>
Looks good, thanks.
Quoted 28 lines
--- gitweb/gitweb.perl | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)gitweb/gitweb.perl +2
-2@@ -2929,7 +2929,7 @@ EOF if (-f $site_header) { open (my $fd, $site_header); - print <$fd>; + print map {to_utf8($_)} <$fd>; close $fd; }@@ -3018,7 +3018,7 @@ sub git_footer_html { if (-f $site_footer) { open (my $fd, $site_footer); - print <$fd>; + print map {to_utf8($_)} <$fd>; close $fd; }Signature · 1 line
1.5.6.5
Quoted 10 lines · Junio C Hamano
Quoted 6 lines · Tatsuki Sugiura
All non-ASCII chars of site_{header,footer} will be broken by perl IO layer without decoding to utf8.
Here is a fix to just call
to_utf8for inputs from these files.Signed-off-by Tatsuki Sugiura <[email protected]>Looks good, thanks.
Hmmm... it is good _partial_ solution. I wonder if gitweb doesn't have the same problem with per-project README.html file...
Quoted 26 lines
Quoted 26 lines
--- gitweb/gitweb.perl | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)gitweb/gitweb.perl +2
-2@@ -2929,7 +2929,7 @@ EOF if (-f $site_header) { open (my $fd, $site_header); - print <$fd>; + print map {to_utf8($_)} <$fd>; close $fd; }@@ -3018,7 +3018,7 @@ sub git_footer_html { if (-f $site_footer) { open (my $fd, $site_footer); - print <$fd>; + print map {to_utf8($_)} <$fd>; close $fd; }
Quoted 2 lines
Quoted 2 lines
Signature · 1 line
1.5.6.5
There was some patch by Recai Oktaş, or Gerrit Pape (or me)
gitweb/gitweb.perl +1 -1
@@ -16,7 +16,7 @@ use Encode; use Fcntl ':mode'; use File::Find qw(); use File::Basename qw(basename); -binmode STDOUT, ':utf8'; +use open qw(:std :utf8); BEGIN { CGI->compile() if $ENV{'MOD_PERL'};
Then to_utf8() wouldn't be necessary. But I'd like for Perl experts to check it first; for example this doesn't allow $fallback_encoding.
Signature · 2 lines
Jakub Narębski Poland
PATCH 1/1 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.
---
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: <[email protected]>
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(-)
gitweb/gitweb.perl +17 -16
@@ -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
Re: [PATCH] gitweb: Fix handling of non-ASCII characters in inserted HTML files
Quoted 13 lines · Jakub Narebski
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()doesto_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 <[email protected]>Signed-off-by Jakub Narebski <[email protected]>
Quoted 7 lines
---
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: <[email protected]>
http://thread.gmane.org/gmane.comp.version-control.git/101199
It may be more complete but it is obviously untested. Please help me trust you better with your future patches. Because I personally do not run gitweb myself, I really need a trustworthy lieutenant(s) in the area.
[Wed Dec 3 01:52:07 2008] gitweb.perl: Global symbol "$fd" requires explicit package name at /git.git/t/../gitweb/gitweb.perl line 4500. [Wed Dec 3 01:52:07 2008] gitweb.perl: Execution of /git.git/t/../gitweb/gitweb.perl aborted due to compilation errors.
Quoted 3 lines
but it is in principle the same solution.
I think this one as it is a bugfix should go in git 1.6.1
Trading a gitweb with a small bug with a gitweb that does not even pass its test script does not feel like a good change to me.
I think the breakage is the "close $fd" at the end of this hunk:
Quoted 9 lines
gitweb/gitweb.perl +0
-5@@ -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"
gitweb/gitweb.perl sub git_summary { · line 4485
Quoted 10 lines
gitweb/gitweb.perl +5
-2- 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
I'll queue it to 'pu', with the "close $fd" removed, for now.
Re: [PATCH] gitweb: Fix handling of non-ASCII characters in inserted HTML files
Quoted 33 lines · Junio C Hamano
Quoted 9 lines · Jakub Narebski
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()doesto_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)".Quoted 6 lines
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: <[email protected]>
http://thread.gmane.org/gmane.comp.version-control.git/101199It may be more complete but it is obviously untested. Please help me trust you better with your future patches. Because I personally do not run gitweb myself, I really need a trustworthy lieutenant(s) in the area.
[Wed Dec 3 01:52:07 2008] gitweb.perl: Global symbol "$fd" requires explicit package name at /git.git/t/../gitweb/gitweb.perl line 4500. [Wed Dec 3 01:52:07 2008] gitweb.perl: Execution of /git.git/t/../gitweb/gitweb.perl aborted due to compilation errors.Quoted 3 lines
but it is in principle the same solution.
I think this one as it is a bugfix should go in git 1.6.1
Trading a gitweb with a small bug with a gitweb that does not even pass its test script does not feel like a good change to me.
I think the breakage is the "close $fd" at the end of this hunk:
[...]
Quoted 1 line
I'll queue it to 'pu', with the "close $fd" removed, for now.
I'm very sorry about that. It was a bit of time since my last patch sent, and I forgot that nevermind how obvious and simple the change, one should run relevant parts of test suite, or at least try to run gitweb / changed command.
With "close $fd" removed the patch is correct (and patches t9500*).
Signature · 2 lines
Jakub Narebski Poland
Re: [PATCH] gitweb: Fix handling of non-ASCII characters in inserted HTML files
Quoted 1 line · Jakub Narebski
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 ;-).
Thanks.
PATCH 1/1 gitweb: Fix bug in insert_file() subroutine
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.
---
Quoted 7 lines · Junio C Hamano
Quoted 2 lines · Jakub Narebski
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(-)
gitweb/gitweb.perl +1 -1
@@ -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; }
t/t9500-gitweb-standalone-no-errors.sh +10 -0
@@ -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
Signature · 2 lines
Stacked GIT 0.14.3 git version 1.6.0.4
Re: [PATCH] gitweb: Fix bug in insert_file() subroutine
t/t9500-gitweb-standalone-no-errors.sh test_expect_success \ · line 685
Quoted 10 lines · Jakub Narebski
t/t9500-gitweb-standalone-no-errors.sh +10
-0+# ---------------------------------------------------------------------- +# 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' +
Yup, a new test would certainly help to catch breakages ;-)
Thanks.