Periods not allowed in CodeIgniter URI?

2019-03-04 14:41发布

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~%\.:_\-';

3条回答
Animai°情兽
2楼-- · 2019-03-04 14:50

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?

查看更多
你好瞎i
3楼-- · 2019-03-04 15:01

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)'] = ...
查看更多
放荡不羁爱自由
4楼-- · 2019-03-04 15:16
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
查看更多
登录 后发表回答