Skip to content

Commit

Permalink
Fix _set_default_controller() not to look in sub-folders
Browse files Browse the repository at this point in the history
_set_default_controller() sets the class and method directly.
That's ok, because we haven't actually defined what it
would mean to have a default route pointing to a sub-folder.
(Does the URL /directory/ cause us to look in a sub-sub-folder?
Could we get into an infinite loop?)

But then it goes ahead and call _set_request(), which may
try to look in sub-folders.  It would then re-set the class
 - and the method.  Unless the default route doesn't specify
a method, in which case it would set a new class but preserve
the old method, producing an inconsistent request.

Split the part of _set_request() we _do_ want into
_set_request_novalidate(), and call that instead.
  • Loading branch information
sourcejedi committed May 11, 2012
1 parent 3b7d997 commit 5a63c68
Showing 1 changed file with 24 additions and 14 deletions.
38 changes: 24 additions & 14 deletions system/core/Router.php
Expand Up @@ -179,31 +179,25 @@ protected function _set_default_controller()
{
show_error('Unable to determine what should be displayed. A default route has not been specified in the routing file.');
}
// Is the method being specified?
if (strpos($this->default_controller, '/') !== FALSE)
{
$x = explode('/', $this->default_controller);
$this->set_class($x[0]);
$this->set_method($x[1]);
$this->_set_request($x);
}
else
$segments = explode('/', $this->default_controller);

if ( ! file_exists(APPPATH.'controllers/'.$segments[0].'.php'))
{
$this->set_class($this->default_controller);
$this->set_method('index');
$this->_set_request(array($this->default_controller, 'index'));
show_404($segments[0]);
}
$this->_set_request_novalidate($segments);

log_message('debug', 'No URI present. Default controller set.');
}

// --------------------------------------------------------------------

/**
* Set the Route
*
* This function takes an array of URI segments as
* input, and sets the current class/method
* input, sets the current class/method, and makes
* sure we know how to find the class.
*
* @param array
* @return void
Expand All @@ -217,6 +211,22 @@ protected function _set_request($segments = array())
return $this->_set_default_controller();
}

$this->_set_request_novalidate($segments);
}

// --------------------------------------------------------------------

/**
* Set the Route
*
* This function takes an array of URI segments as
* input, and sets the current class/method
*
* @param array
* @return void
*/
protected function _set_request_novalidate($segments)
{
$this->set_class($segments[0]);

if ( ! isset($segments[1]))
Expand Down

0 comments on commit 5a63c68

Please sign in to comment.