]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/ViewVCS.pm
hlmod: do_hl* performs src_escape immediately
[public-inbox.git] / lib / PublicInbox / ViewVCS.pm
index 1e8c31f2634adad8ebdaf6c6ae42dc1116054763..f6a769427dfae230a1bd9a3261063768852af999 100644 (file)
 package PublicInbox::ViewVCS;
 use strict;
 use warnings;
-use Encode qw(find_encoding);
 use PublicInbox::SolverGit;
 use PublicInbox::WwwStream;
 use PublicInbox::Linkify;
-use PublicInbox::Hval qw(ascii_html to_filename src_escape);
+use PublicInbox::Hval qw(ascii_html to_filename);
 my $hl = eval {
        require PublicInbox::HlMod;
        PublicInbox::HlMod->new;
 };
 
-# we need to trigger highlight::CodeGenerator::deleteInstance
-# in HlMod::DESTROY before the rest of Perl shuts down to avoid
-# a segfault at shutdown
-END { $hl = undef };
-
 my %QP_MAP = ( A => 'oid_a', B => 'oid_b', a => 'path_a', b => 'path_b' );
 my $max_size = 1024 * 1024; # TODO: configurable
-my $enc_utf8 = find_encoding('UTF-8');
 my $BIN_DETECT = 8000; # same as git
 
 sub html_page ($$$) {
@@ -96,7 +89,6 @@ sub solve_result {
        my $raw_link = "(<a\nhref=$path>raw</a>)";
        if ($size > $max_size) {
                return stream_large_blob($ctx, $res, \$log, $fn) if defined $fn;
-               # TODO: stream the raw file if it's gigantic, at least
                $log = "<pre><b>Too big to show, download available</b>\n" .
                        "$oid $type $size bytes $raw_link</pre>" . $log;
                return html_page($ctx, 500, \$log);
@@ -111,7 +103,7 @@ sub solve_result {
        }
 
        my $binary = index($$blob, "\0") >= 0;
-       if ($fn) {
+       if (defined $fn) {
                my $h = [ 'Content-Length', $size, 'Content-Type' ];
                push(@$h, ($binary ? 'application/octet-stream' : 'text/plain'));
                return delete($ctx->{-wcb})->([200, $h, [ $$blob ]]);
@@ -123,15 +115,14 @@ sub solve_result {
                return html_page($ctx, 200, \$log);
        }
 
-       $$blob = $enc_utf8->decode($$blob);
+       # TODO: detect + convert to ensure validity
+       utf8::decode($$blob);
        my $nl = ($$blob =~ tr/\n/\n/);
        my $pad = length($nl);
 
        $l->linkify_1($$blob);
        my $ok = $hl->do_hl($blob, $path) if $hl;
        if ($ok) {
-               $$ok = $enc_utf8->decode($$ok);
-               src_escape($$ok);
                $blob = $ok;
        } else {
                $$blob = ascii_html($$blob);