gitweb: fix warnings in PATH_INFO code and add export_ok/strict_export
Signed-off-by: Junio C Hamano <junkio@cox.net>
Matthias Lederhofer committed
Sep 17, 2006 at 15:29 UTC
645927cec82253a3592ca738c4a405427a71eb31
1 file changed
+21
-13
gitweb/gitweb.perl
+21
-13
@@ -189,9 +189,6 @@ do $GITWEB_CONFIG if -e $GITWEB_CONFIG;
189
# version of the core git binary
190
our $git_version = qx($GIT --version) =~ m/git version (.*)$/ ? $1 : "unknown";
191
192
-# path to the current git repository
193
-our $git_dir;
194
-
192
$projects_list ||= $projectroot;
193
194
# ======================================================================
@@ -273,30 +270,41 @@ if (defined $searchtext) {
270
}
271
272
# now read PATH_INFO and use it as alternative to parameters
276
-our $path_info = $ENV{"PATH_INFO"};
277
-$path_info =~ s|^/||;
278
-$path_info =~ s|/$||;
279
-if (validate_input($path_info) && !defined $project) {
273
+sub evaluate_path_info {
274
+ return if defined $project;
275
+ my $path_info = $ENV{"PATH_INFO"};
276
+ return if !$path_info;
277
+ $path_info =~ s,(^/|/$),,gs;
278
+ $path_info = validate_input($path_info);
279
+ return if !$path_info;
280
$project = $path_info;
281
while ($project && !-e "$projectroot/$project/HEAD") {
282
$project =~ s,/*[^/]*$,,;
283
}
284
- if (defined $project) {
285
- $project = undef unless $project;
284
+ if (!$project ||
285
+ ($export_ok && !-e "$projectroot/$project/$export_ok") ||
286
+ ($strict_export && !project_in_list($project))) {
287
+ undef $project;
288
+ return;
289
}
290
+ # do not change any parameters if an action is given using the query string
291
+ return if $action;
292
if ($path_info =~ m,^$project/([^/]+)/(.+)$,) {
293
# we got "project.git/branch/filename"
294
$action ||= "blob_plain";
290
- $hash_base ||= $1;
291
- $file_name ||= $2;
295
+ $hash_base ||= validate_input($1);
296
+ $file_name ||= validate_input($2);
297
} elsif ($path_info =~ m,^$project/([^/]+)$,) {
298
# we got "project.git/branch"
299
$action ||= "shortlog";
295
- $hash ||= $1;
300
+ $hash ||= validate_input($1);
301
}
302
}
303
+evaluate_path_info();
304
299
-$git_dir = "$projectroot/$project";
305
+# path to the current git repository
306
+our $git_dir;
307
+$git_dir = "$projectroot/$project" if $project;
308
309
# dispatch
310
my %actions = (