Skip to content

Commit

Permalink
returned http status code 404 in various cases when path is not found…
Browse files Browse the repository at this point in the history
… (issue #321)
  • Loading branch information
dirk-thomas committed Jun 18, 2011
1 parent 97c169e commit d4bb53a
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 13 deletions.
8 changes: 8 additions & 0 deletions blame.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,21 @@
if (!$history) {
unset($vars['error']);
$history = $svnrep->getLog($path, '', '', false, 2, ($path == '/') ? '' : $peg);
if (!$history) {
header('HTTP/1.x 404 Not Found', true, 404);
$vars['error'] = $lang['NOPATH'];
}
}
$youngest = ($history && isset($history->entries[0])) ? $history->entries[0]->rev : false;

if (empty($rev)) {
$rev = $youngest;
} else {
$history = $svnrep->getLog($path, $rev, '', false, 2, $peg);
if (!$history) {
header('HTTP/1.x 404 Not Found', true, 404);
$vars['error'] = $lang['NOPATH'];
}
}

if ($path{0} != '/') {
Expand Down
16 changes: 13 additions & 3 deletions comp.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,20 @@ function checkRevision($rev) {
$vars['rev1'] = $rev1;
$vars['rev2'] = $rev2;

// Set variables used for the more recent of the two revisions
$rev = max($rev1, $rev2);
$history = $svnrep->getLog($path, $rev, $rev, false, 1);
$history1 = $svnrep->getLog($path1, $rev1, $rev1, false, 1);
if (!$history1) {
header('HTTP/1.x 404 Not Found', true, 404);
$vars['error'] = $lang['NOPATH'];
} else {
$history2 = $svnrep->getLog($path2, $rev2, $rev2, false, 1);
if (!$history2) {
header('HTTP/1.x 404 Not Found', true, 404);
$vars['error'] = $lang['NOPATH'];
}
}

// Set variables used for the more recent of the two revisions
$history = ($rev1 >= $rev2 ? $history1 : $history2);
if ($history) {
$logEntry = $history->curEntry;
$vars['rev'] = $logEntry->rev;
Expand Down
11 changes: 6 additions & 5 deletions filedetails.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
unset($vars['error']);
$history = $svnrep->getLog($path, '', '', false, 2, ($path == '/') ? '' : $peg);
if (!$history) {
unset($vars['error']);
$vars['error'] = 'Revision '.$peg.' of this resource does not exist.';
header('HTTP/1.x 404 Not Found', true, 404);
$vars['error'] = $lang['NOPATH'];
}
}
$youngest = ($history && isset($history->entries[0])) ? $history->entries[0]->rev : false;
Expand All @@ -60,7 +60,7 @@
// Check to see if the user has requested that this type be zipped and sent
// to the browser as an attachment

if (isset($zipped) && in_array($extn, $zipped) && $rep->hasReadAccess($path, false)) {
if ($history && isset($zipped) && in_array($extn, $zipped) && $rep->hasReadAccess($path, false)) {
$base = basename($path);
header('Content-Type: application/x-gzip');
header('Content-Disposition: attachment; filename='.urlencode($base).'.gz');
Expand Down Expand Up @@ -95,7 +95,7 @@
}

$useMime = ($mimeType) ? @$_REQUEST['usemime'] : false;
if (!empty($mimeType) && !$useMime) {
if ($history && !empty($mimeType) && !$useMime) {
$useMime = $mimeType; // Save MIME type for later before possibly clobbering
// If a MIME type exists but is set to be ignored, set it to an empty string.
foreach ($config->inlineMimeTypes as $inlineType) {
Expand All @@ -107,7 +107,7 @@
}

// If a MIME type is associated with the file, deliver with Content-Type header.
if (!empty($mimeType) && $rep->hasReadAccess($path, false)) {
if ($history && !empty($mimeType) && $rep->hasReadAccess($path, false)) {
$base = basename($path);
header('Content-Type: '.$mimeType);
//header('Content-Length: '.$size);
Expand Down Expand Up @@ -195,6 +195,7 @@
$vars['error'] = $lang['NOACCESS'];
checkSendingAuthHeader($rep);
} else if (!$svnrep->isFile($path, $rev, $peg)) {
header('HTTP/1.x 404 Not Found', true, 404);
$vars['error'] = $lang['NOPATH'];
}

Expand Down
4 changes: 4 additions & 0 deletions listing.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,10 @@ function showTreeDir($svnrep, $path, $rev, $peg, $listing) {
if (!$history) {
unset($vars['error']);
$history = $svnrep->getLog($path, '', '', false, 2, ($path == '/') ? '' : $peg);
if (!$history) {
header('HTTP/1.x 404 Not Found', true, 404);
$vars['error'] = $lang['NOPATH'];
}
}
$youngest = ($history && isset($history->entries[0])) ? $history->entries[0]->rev : 0;

Expand Down
4 changes: 2 additions & 2 deletions log.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ function removeAccents($string) {
unset($vars['error']);
$history = $svnrep->getLog($path, '', '', false, 1, ($path == '/') ? '' : $peg);
if (!$history) {
unset($vars['error']);
$vars['error'] = 'Revision '.$peg.' of this resource does not exist.';
header('HTTP/1.x 404 Not Found', true, 404);
$vars['error'] = $lang['NOPATH'];
}
}

Expand Down
8 changes: 8 additions & 0 deletions revision.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
if (!$history) {
unset($vars['error']);
$history = $svnrep->getLog($path, '', '', false, 2, ($path == '/') ? '' : $peg);
if (!$history) {
header('HTTP/1.x 404 Not Found', true, 404);
$vars['error'] = $lang['NOPATH'];
}
}
$youngest = ($history && isset($history->entries[0])) ? $history->entries[0]->rev : 0;
$vars['youngestrev'] = $youngest;
Expand All @@ -52,6 +56,10 @@
$lastChangedRev = ($rev) ? $rev : $youngest;
if ($lastChangedRev != $youngest) {
$history = $svnrep->getLog($path, $lastChangedRev, 1, false, 2, $peg);
if (!$history) {
header('HTTP/1.x 404 Not Found', true, 404);
$vars['error'] = $lang['NOPATH'];
}
}
if (empty($rev))
$rev = $lastChangedRev;
Expand Down
11 changes: 8 additions & 3 deletions rss.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,16 @@
exit;
}

header('Content-Type: application/xml; charset=utf-8');

// If there's no revision info, go to the lastest revision for this path
$svnrep = new SVNRepository($rep);
$history = $svnrep->getLog($path, $rev, '', false, $max, $peg);
if (!$history) {
header('HTTP/1.x 404 Not Found', true, 404);
echo $lang['NOPATH'];
exit;
}

header('Content-Type: application/xml; charset=utf-8');

if ($rep->isRssCachingEnabled()) {
// Filename for storing a cached RSS feed for this particular path/revision
Expand All @@ -92,7 +97,7 @@
$rss .= '<link>'.getFullURL($baseurl.$config->getURL($rep, $path, 'log').(@$_REQUEST['isdir'] == 1 ? 'isdir=1&amp;' : '').'max='.$max.'&amp;'.createRevAndPegString($passrev, $peg)).'</link>';
// URL where this original RSS feed can be found
$rss .= '<atom:link href="'.escape(getFullURL($_SERVER['REQUEST_URI'])).'" rel="self" type="application/rss+xml" />'."\n";
if ($history && is_array($history->entries)) {
if (is_array($history->entries)) {
$itemURL = $baseurl.$config->getURL($rep, $path, 'revision');
if (@$_REQUEST['isdir'] == 1 || $path == '' || $path == '/')
$itemURL .= 'isdir=1&amp;';
Expand Down

0 comments on commit d4bb53a

Please sign in to comment.