X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=public-inbox.cgi;h=3c51c314ebe6c4452e84d8fbd3849357c559456f;hb=e022d3377fd2c50fd9931bf96394728958a90bf3;hp=03202c61736afa7887887ab7a8786a8584bc2105;hpb=0e356ebfa0bbbbb2a7582657435cf681d92387f2;p=public-inbox.git diff --git a/public-inbox.cgi b/public-inbox.cgi index 03202c61..3c51c314 100755 --- a/public-inbox.cgi +++ b/public-inbox.cgi @@ -12,10 +12,11 @@ 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); +my $enc_utf8 = find_encoding('UTF-8'); our $LISTNAME_RE = qr!\A/([\w\.\-]+)!; our $pi_config; BEGIN { @@ -56,7 +57,7 @@ sub main { 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 "/") { @@ -65,9 +66,7 @@ sub main { 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 @@ -80,7 +79,7 @@ sub main { } 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); @@ -114,8 +113,7 @@ sub invalid_list_mid { 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; @@ -170,8 +168,9 @@ sub get_mid_html { 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)]; @@ -215,6 +214,6 @@ sub set_binmode { # 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)'; } }