From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 65F1B21431 for ; Mon, 21 Jan 2019 20:52:58 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 21/37] view: enforce trailing slash for /$INBOX/$OID/s/ endpoints Date: Mon, 21 Jan 2019 20:52:37 +0000 Message-Id: <20190121205253.10455-22-e@80x24.org> In-Reply-To: <20190121205253.10455-1-e@80x24.org> References: <20190121205253.10455-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: As with our use of the trailing slash in $MESSAGE_ID/T/ and '$MESSAGE_ID/t/' endpoints, this for 'wget -r --mirror' compatibility as well as allowing sysadmins to quickly stand up a static directory with "index.html" in it to reduce load. --- lib/PublicInbox/ViewDiff.pm | 8 ++++---- lib/PublicInbox/ViewVCS.pm | 4 ++-- lib/PublicInbox/WWW.pm | 6 ++++-- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/PublicInbox/ViewDiff.pm b/lib/PublicInbox/ViewDiff.pm index 94f015f..1aad283 100644 --- a/lib/PublicInbox/ViewDiff.pm +++ b/lib/PublicInbox/ViewDiff.pm @@ -45,12 +45,12 @@ sub diff_hunk ($$$$) { my ($n) = ($ca =~ /^-(\d+)/); $n = defined($n) ? do { ++$n; "#n$n" } : ''; - my $rv = qq(@@ {Q}$n>$ca); + my $rv = qq(@@ {Q}$n>$ca); ($n) = ($cb =~ /^\+(\d+)/); $n = defined($n) ? do { ++$n; "#n$n" } : ''; - $rv .= qq( {Q}$n>$cb @@); + $rv .= qq( {Q}$n>$cb @@); } sub flush_diff ($$$$) { @@ -90,11 +90,11 @@ sub flush_diff ($$$$) { } $$dst .= to_html($linkify, $s); } elsif ($s =~ s/^(index $OID_NULL\.\.)($OID_BLOB)\b//o) { - $$dst .= qq($1{Q}>$2); + $$dst .= qq($1{Q}>$2); $$dst .= to_html($linkify, $s) ; } elsif ($s =~ s/^index ($OID_NULL)(\.\.$OID_BLOB)\b//o) { $$dst .= 'index '; - $$dst .= qq({Q}>$1$2); + $$dst .= qq({Q}>$1$2); $$dst .= to_html($linkify, $s); } elsif ($s =~ /^index ($OID_BLOB)\.\.($OID_BLOB)/o) { $dctx->{oid_a} = $1; diff --git a/lib/PublicInbox/ViewVCS.pm b/lib/PublicInbox/ViewVCS.pm index 90c0907..61f4deb 100644 --- a/lib/PublicInbox/ViewVCS.pm +++ b/lib/PublicInbox/ViewVCS.pm @@ -27,7 +27,7 @@ my $enc_utf8 = find_encoding('UTF-8'); sub html_page ($$$) { my ($ctx, $code, $strref) = @_; - $ctx->{-upfx} = '../'; # from "/$INBOX/$OID/s" + $ctx->{-upfx} = '../../'; # from "/$INBOX/$OID/s/" PublicInbox::WwwStream->response($ctx, $code, sub { my ($nr, undef) = @_; $nr == 1 ? $$strref : undef; @@ -82,7 +82,7 @@ sub show ($$;$) { } my $path = to_filename($di->{path_b} || $hints->{path_b} || 'blob'); - my $raw_link = "(raw)"; + my $raw_link = "(raw)"; if ($binary) { $log = "
$oid $type $size bytes (binary)" .
 			" $raw_link
" . $log; diff --git a/lib/PublicInbox/WWW.pm b/lib/PublicInbox/WWW.pm index c73370f..a0fd7fa 100644 --- a/lib/PublicInbox/WWW.pm +++ b/lib/PublicInbox/WWW.pm @@ -118,10 +118,12 @@ sub call { r301($ctx, $1, $2); } elsif ($path_info =~ m!$INBOX_RE/_/text(?:/(.*))?\z!o) { get_text($ctx, $1, $2); - } elsif ($path_info =~ m!$INBOX_RE/($OID_RE)/s\z!o) { + } elsif ($path_info =~ m!$INBOX_RE/($OID_RE)/s/\z!o) { get_vcs_object($ctx, $1, $2); - } elsif ($path_info =~ m!$INBOX_RE/($OID_RE)/_([\w\.\-]+)\z!o) { + } elsif ($path_info =~ m!$INBOX_RE/($OID_RE)/s/([\w\.\-]+)\z!o) { get_vcs_object($ctx, $1, $2, $3); + } elsif ($path_info =~ m!$INBOX_RE/($OID_RE)/s\z!o) { + r301($ctx, $1, $2, 's/'); # convenience redirects order matters } elsif ($path_info =~ m!$INBOX_RE/([^/]{2,})\z!o) { r301($ctx, $1, $2); -- EW