use 5.008;
use strict;
use warnings;
-use CGI qw(:cgi :escapeHTML -nosticky); # PSGI/FastCGI/mod_perl compat
-use Encode qw(decode_utf8);
+use CGI qw(:cgi -nosticky); # PSGI/FastCGI/mod_perl compat
+use Encode qw(find_encoding);
use PublicInbox::Config;
use URI::Escape qw(uri_escape uri_unescape);
-use Digest::SHA qw(sha1_hex);
+my $enc_utf8 = find_encoding('UTF-8');
our $LISTNAME_RE = qr!\A/([\w\.\-]+)!;
our $pi_config;
BEGIN {
if ($cgi->request_method !~ /\AGET|HEAD\z/) {
return r("405 Method Not Allowed");
}
- my $path_info = decode_utf8($cgi->path_info);
+ my $path_info = $enc_utf8->decode($cgi->path_info);
# top-level indices and feeds
if ($path_info eq "/") {
invalid_list(\%ctx, $1) || redirect_list_index(\%ctx, $cgi);
} elsif ($path_info =~ m!$LISTNAME_RE(?:/|/index\.html)?\z!o) {
invalid_list(\%ctx, $1) || get_index(\%ctx, $cgi, 0);
- } elsif ($path_info =~ m!$LISTNAME_RE/index\.atom\.xml\z!o) {
- invalid_list(\%ctx, $1) || get_atom(\%ctx, $cgi, 1);
- } elsif ($path_info =~ m!$LISTNAME_RE/all\.atom\.xml\z!o) {
+ } elsif ($path_info =~ m!$LISTNAME_RE/atom\.xml\z!o) {
invalid_list(\%ctx, $1) || get_atom(\%ctx, $cgi, 0);
# single-message pages
} elsif ($path_info =~ m!$LISTNAME_RE/f/(\S+)\.html\z!o) {
invalid_list_mid(\%ctx, $1, $2) || get_full_html(\%ctx, $cgi);
- # convenience redirect
+ # convenience redirects, order matters
} elsif ($path_info =~ m!$LISTNAME_RE/(?:m|f)/(\S+)\z!o) {
invalid_list_mid(\%ctx, $1, $2) || redirect_mid(\%ctx, $cgi);
if (defined $git_dir) {
$ctx->{git_dir} = $git_dir;
$ctx->{listname} = $listname;
- return undef;
+ return;
}
r404();
}
undef;
}
-# /$LISTNAME/index.atom.xml -> Atom feed
-# /$LISTNAME/all.atom.xml -> Atom feed, includes replies
+# /$LISTNAME/atom.xml -> Atom feed, includes replies
sub get_atom {
my ($ctx, $cgi, $top) = @_;
require PublicInbox::Feed;
sub mid2blob {
my ($ctx) = @_;
local $ENV{GIT_DIR} = $ctx->{git_dir};
- my $hex = sha1_hex($ctx->{mid});
+ require Digest::SHA;
+ my $hex = Digest::SHA::sha1_hex($ctx->{mid});
$hex =~ /\A([a-f0-9]{2})([a-f0-9]{38})\z/i or
die "BUG: not a SHA-1 hex: $hex";
my $blob = `git cat-file blob HEAD:$1/$2 2>/dev/null`;
my $x = mid2blob($ctx);
return r404() unless $x;
- my $pfx = "../f/" . uri_escape($ctx->{mid}) . ".html";
require PublicInbox::View;
+ my $mid_href = PublicInbox::Hval::ascii_html(uri_escape($ctx->{mid}));
+ my $pfx = "../f/$mid_href.html";
require Email::MIME;
[ "200 OK", {'Content-Type' => 'text/html'},
PublicInbox::View->as_html(Email::MIME->new($$x), $pfx)];
# no way to validate raw messages, mixed encoding is possible.
binmode STDOUT;
} else { # strict encoding for HTML and XML
- binmode STDOUT, ':encoding(UTF-8)';
+ binmode STDOUT, ':encoding(us-ascii)';
}
}