public inbox for git@vger.kernel.org 
 help / color / mirror / Atom feed
From: jk@blackdown•de (Jürgen Kreileder)
To: git@vger•kernel.org
Subject: [PATCH 1/4] gitweb: Fix utf8 encoding for blob_plain, blobdiff_plain, commitdiff_plain, and patch
Date: Mon, 08 Apr 2013 22:08:20 +0200	[thread overview]
Message-ID: <m2zjx8bxaj.fsf@blackdown.de> (raw)

Fixes the encoding for several _plain actions and for text/* and */*+xml blobs. 

Signed-off-by: Jürgen Kreileder <jk@blackdown•de>
---
 gitweb/gitweb.perl |    8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 1309196..9cfe5b5 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -3823,7 +3823,7 @@ sub blob_contenttype {
 	my ($fd, $file_name, $type) = @_;
 
 	$type ||= blob_mimetype($fd, $file_name);
-	if ($type eq 'text/plain' && defined $default_text_plain_charset) {
+	if (($type =~ m!^text/\w[-\w]*$! || $type =~ m!^\w[-\w]*/\w[-\w]*\+xml$!) && defined $default_text_plain_charset) {
 		$type .= "; charset=$default_text_plain_charset";
 	}
 
@@ -7637,7 +7637,9 @@ sub git_blobdiff {
 			last if $line =~ m!^\+\+\+!;
 		}
 		local $/ = undef;
+		binmode STDOUT, ':raw';
 		print <$fd>;
+		binmode STDOUT, ':utf8'; # as set at the beginning of gitweb.cgi
 		close $fd;
 	}
 }
@@ -7884,12 +7886,16 @@ sub git_commitdiff {
 
 	} elsif ($format eq 'plain') {
 		local $/ = undef;
+		binmode STDOUT, ':raw';
 		print <$fd>;
+		binmode STDOUT, ':utf8'; # as set at the beginning of gitweb.cgi
 		close $fd
 			or print "Reading git-diff-tree failed\n";
 	} elsif ($format eq 'patch') {
 		local $/ = undef;
+		binmode STDOUT, ':raw';
 		print <$fd>;
+		binmode STDOUT, ':utf8'; # as set at the beginning of gitweb.cgi
 		close $fd
 			or print "Reading git-format-patch failed\n";
 	}
-- 
1.7.10.4

             reply	other threads:[~2013-04-08 20:09 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-08 20:08 Jürgen Kreileder [this message]
2013-04-08 21:58 ` [PATCH 1/4] gitweb: Fix utf8 encoding for blob_plain, blobdiff_plain, commitdiff_plain, and patch Junio C Hamano
2013-04-09 11:31   ` Jakub Narębski
2013-04-09 21:59     ` Jürgen Kreileder
2013-04-10 10:23       ` Jakub Narębski

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=m2zjx8bxaj.fsf@blackdown.de \
    --to=jk@blackdown$(echo .)de \
    --cc=git@vger$(echo .)kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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