From: Eric Wong Date: Mon, 18 Jan 2016 23:44:40 +0000 (+0000) Subject: repobrowse: display text/plain as UTF-8 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=66ad0a45c58ed63ec16a35f41f3eda7cb8917c50;p=thirdparty%2Fpublic-inbox.git repobrowse: display text/plain as UTF-8 We'll be UTF-8 imperialists for now and assume all of our textual output is UTF-8 for the benefit of browsers. --- diff --git a/lib/PublicInbox/RepobrowseGitBlob.pm b/lib/PublicInbox/RepobrowseGitBlob.pm index e890ae847..f2b38a0c3 100644 --- a/lib/PublicInbox/RepobrowseGitBlob.pm +++ b/lib/PublicInbox/RepobrowseGitBlob.pm @@ -27,7 +27,7 @@ sub call_git_blob { if ($type eq 'blob') { $type = git_blob_mime_type($self, $req, $cat, \$buf, \$left); } elsif ($type eq 'commit' || $type eq 'tag') { - $type = 'text/plain'; + $type = 'text/plain; charset=UTF-8'; } else { $type = 'application/octet-stream'; } @@ -49,7 +49,8 @@ sub git_blob_mime_type { return; } $$left -= $r; - (index($buf, "\0") < 0) ? 'text/plain' : 'application/octet-stream'; + (index($buf, "\0") < 0) ? 'text/plain; charset=UTF-8' + : 'application/octet-stream'; } sub git_blob_stream_response { diff --git a/lib/PublicInbox/RepobrowseGitPatch.pm b/lib/PublicInbox/RepobrowseGitPatch.pm index 4cb059607..b67fb86f0 100644 --- a/lib/PublicInbox/RepobrowseGitPatch.pm +++ b/lib/PublicInbox/RepobrowseGitPatch.pm @@ -33,7 +33,8 @@ sub call_git_patch { return unless (defined $n && $n > 0); sub { my ($res) = @_; # Plack callback - my $fh = $res->([200, ['Content-Type' => 'text/plain']]); + my $fh = $res->([200, [ + 'Content-Type' => 'text/plain; charset=UTF-8']]); $fh->write($buf); while (1) { $n = read($fp, $buf, 8192); diff --git a/t/repobrowse_git_plain.t b/t/repobrowse_git_plain.t index 23c9e0f50..27347f70b 100644 --- a/t/repobrowse_git_plain.t +++ b/t/repobrowse_git_plain.t @@ -21,7 +21,8 @@ test_psgi($test->{app}, sub { $req = 'http://example.com/test.git/plain/foo.txt'; my $blob = $cb->(GET($req)); - is($blob->header('Content-Type'), 'text/plain', 'got text/plain blob'); + like($blob->header('Content-Type'), qr!\Atext/plain\b!, + 'got text/plain blob'); is($blob->content, "-----\nhello\nworld\n", 'raw blob passed'); });