#! /bin/sh /usr/share/dpatch/dpatch-run
## 02_allow_cgiless_execution.dpatch by Martin Schulze <joey@infodrom.org>
##
## All lines beginning with `## DP:' are a description of the patch.
## DP: * cvsweb.cgi: Add support for CGI-less execution. See bug #247452
## DP: at http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=247452.

@DPATCH@
diff -urNad cvsweb-3.0.6~/cvsweb.cgi cvsweb-3.0.6/cvsweb.cgi
--- cvsweb-3.0.6~/cvsweb.cgi	2005-12-31 02:33:31.000000000 +0100
+++ cvsweb-3.0.6/cvsweb.cgi	2005-12-31 02:35:29.000000000 +0100
@@ -299,10 +299,10 @@
 $where         =  $pathinfo;
 $doCheckout    =  $where =~ s|^/$CheckoutMagic/|/|o;
 $where         =~ s|^/||;
-$scriptname    =~ s|^/*|/|;
+$scriptname    =~ s|^/+|/|;
 
 # Let's workaround thttpd's stupidity..
-if ($scriptname =~ m|/$|) {
+if ($ENV{'SERVER_SOFTWARE'} =~ m|thttpd| && $scriptname =~ m|/$|) {
   $pathinfo .= '/';
   my $re = quotemeta $pathinfo;
   $scriptname =~ s/$re$//;
@@ -312,7 +312,7 @@
 # $where      : the path in the CVS repository (without leading /, or only /)
 # $scriptwhere: the URI escaped $scriptname + '/' + $where
 $scriptname   = uri_escape_path($scriptname);
-$scriptwhere  = join('/', $scriptname, uri_escape_path($where));
+$scriptwhere  = join('/', $scriptname, uri_escape_path($where)) if ($where);
 $where        = '/' if ($where eq '');
 
 # In text-based browsers, it's very annoying to have two links per file;
@@ -379,6 +379,7 @@
 
 my %query = ();
 if (defined($ENV{QUERY_STRING})) {
+  $ENV{QUERY_STRING} = uri_unescape($ENV{QUERY_STRING});
   for my $p (split(/[;&]+/, $ENV{QUERY_STRING})) {
     next unless $p;
     $p =~ y/+/ /;
