# [PATCH] gitweb: accept trailing "/" in $project_list

2 messages from 2012-01-04 to 2012-01-04. Participants: Matthieu Moy, Junio C Hamano.
Thread: https://gitlist.dev/t/29291

## Matthieu Moy, 2012-01-04 10:07

Subject: [PATCH] gitweb: accept trailing "/" in $project_list
Message-ID: <1325671665-16847-1-git-send-email-Matthieu.Moy@imag.fr>
URL: https://gitlist.dev/e/1325671665-16847-1-git-send-email-Matthieu.Moy%40imag.fr

```
The current code is removing the trailing "/", but computing the string
length on the previous value, i.e. with the trailing "/". Later in the
code, we do

  my $path = substr($File::Find::name, $pfxlen + 1);

And the "$pfxlen + 1" is supposed to mean "the length of the prefix, plus
1 for the / separating the prefix and the path", but with an incorrect
$pfxlen, this basically eats the first character of the path, and yields
"404 - No projects found".

While we're there, also fix $pfxdepth to use $dir, although a change of 1
in the depth shouldn't really matter.

Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>
---
I'm not fluent in Perl, and not familiar at all with gitweb, but this
sounds a rather obvious (too obvious?) fix.

 gitweb/gitweb.perl |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index f80f259..4512b89 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -2835,8 +2835,8 @@ sub git_get_projects_list {
 		my $dir = $projects_list;
 		# remove the trailing "/"
 		$dir =~ s!/+$!!;
-		my $pfxlen = length("$projects_list");
-		my $pfxdepth = ($projects_list =~ tr!/!!);
+		my $pfxlen = length("$dir");
+		my $pfxdepth = ($dir =~ tr!/!!);
 		# when filtering, search only given subdirectory
 		if ($filter) {
 			$dir .= "/$filter";
-- 
1.7.8.384.g29bb3

```

## Junio C Hamano, 2012-01-04 17:51

Subject: Re: [PATCH] gitweb: accept trailing "/" in $project_list
Message-ID: <7v39bvqru5.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7v39bvqru5.fsf%40alter.siamese.dyndns.org
In-Reply-To: <1325671665-16847-1-git-send-email-Matthieu.Moy@imag.fr>

```
Matthieu Moy <Matthieu.Moy@imag.fr> writes:

> The current code is removing the trailing "/", but computing the string
> length on the previous value, i.e. with the trailing "/". Later in the
> code, we do
>
>   my $path = substr($File::Find::name, $pfxlen + 1);
>
> And the "$pfxlen + 1" is supposed to mean "the length of the prefix, plus
> 1 for the / separating the prefix and the path", but with an incorrect
> $pfxlen, this basically eats the first character of the path, and yields
> "404 - No projects found".
>
> While we're there, also fix $pfxdepth to use $dir, although a change of 1
> in the depth shouldn't really matter.
>
> Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>
> ---
> I'm not fluent in Perl, and not familiar at all with gitweb, but this
> sounds a rather obvious (too obvious?) fix.

Yeah, probably not many people use $project_maxdepth with a meaningful
value.

```
