]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
repobrowse: display text/plain as UTF-8
authorEric Wong <e@80x24.org>
Mon, 18 Jan 2016 23:44:40 +0000 (23:44 +0000)
committerEric Wong <e@80x24.org>
Tue, 5 Apr 2016 18:58:27 +0000 (18:58 +0000)
We'll be UTF-8 imperialists for now and assume all of our
textual output is UTF-8 for the benefit of browsers.

lib/PublicInbox/RepobrowseGitBlob.pm
lib/PublicInbox/RepobrowseGitPatch.pm
t/repobrowse_git_plain.t

index e890ae847e584209a2903b6118aa189071cf32e3..f2b38a0c32ca01a07d5522eded44b4a18c198c8e 100644 (file)
@@ -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 {
index 4cb059607164a3b40772913cdbcccfab34b78b5f..b67fb86f0b34cfcbee740c3f45459cbaeb954211 100644 (file)
@@ -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);
index 23c9e0f50ae6eb566a362d6d059db229d05c16e4..27347f70b2a9045fbc7d1259668e53908ce3570b 100644 (file)
@@ -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');
 });