Welcome Guest, Not a member yet? Register   Sign In
Query String Negates Default Controller
#1

[eluser]Michael Wales[/eluser]
I ran into a small bug while working on a Facebook application - view the bug report.

Description
If query strings are enabled and any query string is passed, CodeIgniter assumes the GET variable defined in config.php will exist. If that variable does not exist, the framework fails to fallback on the default_controller as defined in routes.php.

To reproduce, enable query strings on an application and append ?test=test to the URL.

To fix, the first 20-25 lines of _set_routing() in the code sampled included with this report should be used.

Changelog:
- Moved the loading of routes to the beginning of function to ensure availability.

- Alter the query_string check, so a request without a controller_trigger could enter the conditional.

- Set the current controller to default_controller by default immediately. The default_method being set to index() is already handled elsewhere by the framework.

- Added a conditional to determine if the GET variable exists, and if so - set the current controller to that variable.


How this was noticed:
Working on a Facebook application (which requires query strings). I pointed the application to my application’s default URL, Facebook called it with a ton of it’s own GET variables and obviously no variable named c.

I could see other instances in which this could also be an issue, especially with the API and hosted application services really starting to take off.


Code Sample
Code:
function _set_routing()
{
  // Load the routes.php file.
  @include(APPPATH.'config/routes'.EXT);
  $this->routes = ( ! isset($route) OR ! is_array($route)) ? array() : $route;
  unset($route);
    
    
  // Are query strings enabled in the config file?
  // If so, we're done since segment based URIs are not used with query strings.
  if ($this->config->item('enable_query_strings') === TRUE)
  {

    // Set the controller to the default_controller, we'll then try and
    // load a controller if the GET variable is defined
    $this->set_class(trim(strtolower($this->routes['default_controller'])));
            
    if (isset($_GET[$this->config->item('controller_trigger')]))
    {
      $this->set_class(trim($this->uri->_filter_uri($_GET[$this->config->item('controller_trigger')])));
    }

    if (isset($_GET[$this->config->item('function_trigger')]))
    {
      $this->set_method(trim($this->uri->_filter_uri($_GET[$this->config->item('function_trigger')])));
    }
            
    return;
  }

  // ... rest of function remains as normal ... //


Expected Result
Since the controller_trigger variable does not exist, CodeIgniter should call the default_controller as defined in routes.php.


Actual Result
A CodeIgniter error is thrown (can’t remember which, I think it just the “page could not be found” error).




Theme © iAndrew 2016 - Forum software by © MyBB