gitweb: Fix actionless dispatch for non-existent objects
When gitweb URL does not provide action explicitly, e.g. http://git.example.org/repo.git/branch dispatch() tries to guess action (view to be used) based on remaining parameters. Among others it is based on the type of requested object, which gave problems when asking for non-existent branch or file (for example misspelt name). Now undefined $action from dispatch() should not result in problems. Signed-off-by: Jakub Narebski <jnareb@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jakub Narebski committed
Jan 7, 2012 at 11:47 UTC
18ab83e8568878edc3f6680ebdf439ccaa5bf5db
2 files changed
+11
-1
gitweb/gitweb.perl
+3
-1
@@ -1122,8 +1122,10 @@ sub dispatch {
1122
if (!defined $action) {
1123
if (defined $hash) {
1124
$action = git_get_type($hash);
1125
+ $action or die_error(404, "Object does not exist");
1126
} elsif (defined $hash_base && defined $file_name) {
1127
$action = git_get_type("$hash_base:$file_name");
1128
+ $action or die_error(404, "File or directory does not exist");
1129
} elsif (defined $project) {
1130
$action = 'summary';
1131
} else {
@@ -2364,7 +2366,7 @@ sub get_feed_info {
2366
return unless (defined $project);
2367
# some views should link to OPML, or to generic project feed,
2368
# or don't have specific feed yet (so they should use generic)
2367
- return if ($action =~ /^(?:tags|heads|forks|tag|search)$/x);
2369
+ return if (!$action || $action =~ /^(?:tags|heads|forks|tag|search)$/x);
2370
2371
my $branch;
2372
# branches refs uses 'refs/heads/' prefix (fullname) to differentiate
t/t9500-gitweb-standalone-no-errors.sh
+8
@@ -403,6 +403,14 @@ test_expect_success \
403
'path_info: project/branch:dir/' \
404
'gitweb_run "" "/.git/master:foo/"'
405
406
+test_expect_success \
407
+ 'path_info: project/branch (non-existent)' \
408
+ 'gitweb_run "" "/.git/non-existent"'
409
+
410
+test_expect_success \
411
+ 'path_info: project/branch:filename (non-existent branch)' \
412
+ 'gitweb_run "" "/.git/non-existent:non-existent"'
413
+
414
test_expect_success \
415
'path_info: project/branch:file (non-existent)' \
416
'gitweb_run "" "/.git/master:non-existent"'