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 ($$$) {
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);
}
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 ]]);
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);