]> Sergey Matveev's repositories - public-inbox.git/commitdiff
view: enforce trailing slash for /$INBOX/$OID/s/ endpoints
authorEric Wong <e@80x24.org>
Sat, 19 Jan 2019 08:54:42 +0000 (08:54 +0000)
committerEric Wong <e@80x24.org>
Sun, 20 Jan 2019 04:24:54 +0000 (04:24 +0000)
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
lib/PublicInbox/ViewVCS.pm
lib/PublicInbox/WWW.pm

index 94f015f47a3c66f3a920d80ae97757d054333a3b..1aad2832bb392dbb650f9d839bcde026bb3cf3a7 100644 (file)
@@ -45,12 +45,12 @@ sub diff_hunk ($$$$) {
        my ($n) = ($ca =~ /^-(\d+)/);
        $n = defined($n) ? do { ++$n; "#n$n" } : '';
 
-       my $rv = qq(@@ <a\nhref=$spfx$oid_a/s$dctx->{Q}$n>$ca</a>);
+       my $rv = qq(@@ <a\nhref=$spfx$oid_a/s/$dctx->{Q}$n>$ca</a>);
 
        ($n) = ($cb =~ /^\+(\d+)/);
        $n = defined($n) ? do { ++$n; "#n$n" } : '';
 
-       $rv .= qq( <a\nhref=$spfx$oid_b/s$dctx->{Q}$n>$cb</a> @@);
+       $rv .= qq( <a\nhref=$spfx$oid_b/s/$dctx->{Q}$n>$cb</a> @@);
 }
 
 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<a\nhref=$spfx$2/s$dctx->{Q}>$2</a>);
+                       $$dst .= qq($1<a\nhref=$spfx$2/s/$dctx->{Q}>$2</a>);
                        $$dst .= to_html($linkify, $s) ;
                } elsif ($s =~ s/^index ($OID_NULL)(\.\.$OID_BLOB)\b//o) {
                        $$dst .= 'index ';
-                       $$dst .= qq(<a\nhref=$spfx$1/s$dctx->{Q}>$1</a>$2);
+                       $$dst .= qq(<a\nhref=$spfx$1/s/$dctx->{Q}>$1</a>$2);
                        $$dst .= to_html($linkify, $s);
                } elsif ($s =~ /^index ($OID_BLOB)\.\.($OID_BLOB)/o) {
                        $dctx->{oid_a} = $1;
index 90c09078beb4bd759c47430a4434fce1faf0b360..61f4debadda6dc5257e703fd4807fc2a0a9f269e 100644 (file)
@@ -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 = "(<a\nhref=_$path>raw</a>)";
+       my $raw_link = "(<a\nhref=$path>raw</a>)";
        if ($binary) {
                $log = "<pre>$oid $type $size bytes (binary)" .
                        " $raw_link</pre>" . $log;
index c73370f9a233d82d7c89fc10e7937e87154465e6..a0fd7fa74b99a3dbb099d8c8f68b7cd269d29145 100644 (file)
@@ -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);