X-Git-Url: https://git.deb.at/?p=pkg%2Fblosxom.git;a=blobdiff_plain;f=blosxom.cgi;h=48ee5c1f7668cf7bd136522e887a29d9934f0a2f;hp=068b7183d1afb9f85010de247d56f428670346e7;hb=011c1f0a1750d2ff913302a3e5768de9287f0b0c;hpb=364a736f0bce810faa7f809d4eb6cd74c2972d5b diff --git a/blosxom.cgi b/blosxom.cgi index 068b718..48ee5c1 100755 --- a/blosxom.cgi +++ b/blosxom.cgi @@ -84,8 +84,17 @@ my $fh = new FileHandle; @num2month = sort { $month2num{$a} <=> $month2num{$b} } keys %month2num; # Use the stated preferred URL or figure it out automatically -$url ||= url(); -$url =~ s/^included:/http:/; # Fix for Server Side Includes (SSI) +$url ||= url(-path_info => 1); +$url =~ s/^included:/http:/ if $ENV{SERVER_PROTOCOL} eq 'INCLUDED'; + +# NOTE: Since v3.12, it looks as if CGI.pm misbehaves for SSIs and +# always appends path_info to the url. To fix this, we always +# request an url with path_info, and always remove it from the end of the +# string. +my $pi_len = length $ENV{PATH_INFO}; +my $might_be_pi = substr($url, -$pi_len); +substr($url, -length $ENV{PATH_INFO}) = '' if $might_be_pi eq $ENV{PATH_INFO}; + $url =~ s!/$!!; # Drop ending any / from dir settings @@ -134,13 +143,20 @@ $template = return join '', <$fh> if $fh->open("< $datadir/$path/$chunk.$flavour"); } while ($path =~ s/(\/*[^\/]*)$// and $1); - return join '', ($template{$flavour}{$chunk} || $template{error}{$chunk} || ''); + # Check for definedness, since flavour can be the empty string + if (defined $template{$flavour}{$chunk}) { + return $template{$flavour}{$chunk}; + } elsif (defined $template{error}{$chunk}) { + return $template{error}{$chunk} + } else { + return ''; + } }; # Bring in the templates %template = (); while () { last if /^(__END__)$/; - my($ct, $comp, $txt) = /^(\S+)\s(\S+)\s(.*)$/ or next; + my($ct, $comp, $txt) = /^(\S+)\s(\S+)(?:\s(.*))?$/ or next; $txt =~ s/\\n/\n/mg; $template{$ct}{$comp} .= $txt . "\n"; } @@ -347,7 +363,7 @@ sub generate { ($path,$fn) = $path_file =~ m!^$datadir/(?:(.*)/)?(.*)\.$file_extension!; # Only stories in the right hierarchy - $path =~ /^$currentdir/ or $path_file eq "$datadir/$currentdir" or next; + $path =~ /^$currentdir(?=$|/)/ or $path_file eq "$datadir/$currentdir" or next; # Prepend a slash for use in templates only if a path exists $path &&= "/$path";