0

So after reading this question on API versioning, I decided to prefix all my routes with a version number:

http://localhost/api/1.0/user/login

But when I throw an exception within Exceptions Core, it says that the route is:

10/UserControll...

I've tried escaping the period, but this did not work. Can anyone replicate this problem and think of a possible solution for it?

This is the route I am using for the above:

$route['1.0/user/(:any)'] = '1.0/UserController/$1';

These are my permitted URI chars:

$config['permitted_uri_chars'] = 'a-z 0-9~%\.:_\-';
Community
  • 1
  • 1
NobleUplift
  • 5,631
  • 8
  • 45
  • 87
  • Can you paste a sample route with the prefix from your routes.php? – user1190992 Nov 25 '13 at 20:33
  • I added an example route. – NobleUplift Nov 25 '13 at 21:06
  • What do you mean by throwing an exception within Exceptions core? When I use `$this->uri->uri_string()` in the controller, it shows the URI correctly. I'm not clear on what you're trying to do (and I'm not going to read that HUGE post in the link you added). – minboost Nov 26 '13 at 00:26
  • In `system/core/Exceptions.php` I added a `throw new Exception()` to see what route was causing the 404, and it showed a route without a period. I cannot use `uri_string()` in my controller because CodeIgniter never reaches my controller. – NobleUplift Nov 27 '13 at 15:01

3 Answers3

3
Open libraries/Input.php (system/core/Input.php in CI version 2.0+) and locate function _clean_input_keys($str){, The whole block should look like so:

function _clean_input_keys($str)
{
    if ( ! preg_match("/^[a-z0-9:_\/-]+$/i", $str))
    {
        exit('Disallowed Key Characters.');
    }

    return $str;
}

Check if this has '.' in the preg_match. If not add it, so that your regular expression look like this-

/^[a-z0-9:_\/-\.]+$/i
awsumnik
  • 116
  • 4
  • This brought me closer to figuring out why this is happening. The problem isn't the route, as I mistakenly said earlier, the problem is the controller path that is losing the period. – NobleUplift Nov 27 '13 at 15:27
  • awsumnik, you need to escape "-" symbol if it's not the first or the last in the expression, so the valid regexp is "/^[a-z0-9:_\/.-]+$/i" – bearoff Nov 28 '14 at 15:31
1

Do you have the (.) in your

$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-';

And what is your controller name ?

I think you must have the controller name in your route before the method name.

Something like this :

$route['controller_name/1.0/user/(:any)'] = ...
Chiribuc
  • 88
  • 1
  • 1
  • 8
  • Yes, I do have '.' in my permitted URL chars. `User` is the name of my controller. If I change the controller to `1-0/User/$1`, it works, but not with periods. – NobleUplift Nov 27 '13 at 14:59
  • It isn't a URL problem. The URL reads the route just fine. It's a period in the controller's path that's breaking it. You can have folders prefix the controller name. – NobleUplift Nov 27 '13 at 15:28
1

The problem is on line 468 of system/core/Router.php. Change set_directory from this:

$this->directory = str_replace(array('/', '.'), '', $dir).'/';

To this:

$this->directory = str_replace(array('/'), '', $dir).'/';

Anyone have a guess or gander as to why the Router removes periods from directory names?

NobleUplift
  • 5,631
  • 8
  • 45
  • 87