From f82593fc84a6773cd6fcb0633fdcca4cee92859f Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 19 Jan 2019 08:54:42 +0000 Subject: view: enforce trailing slash for /$INBOX/$OID/s/ endpoints 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(-) (limited to 'lib') diff --git a/lib/PublicInbox/ViewDiff.pm b/lib/PublicInbox/ViewDiff.pm index 94f015f4..1aad2832 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 90c09078..61f4deba 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 c73370f9..a0fd7fa7 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); -- cgit v1.2.3-24-ge0c7