Welcome Guest, Not a member yet? Register   Sign In
permitted_uri_chars single quote
#1

[eluser]unosoft[/eluser]
I need to add single quote in permitted_uri_chars in config.php. How do I do that? I tried several things (' \' and others), but it did not work.

I get the following error:
Severity: Warning

Message: preg_match() [function.preg-match]: Compilation failed: range out of order in character class at offset 17

Filename: libraries/Router.php

Line Number: 408

I am using ajax to pass on the string to the controller.

Thanks
Unosoft
#2

[eluser]unosoft[/eluser]
Come on...there should some way to achieve this. For now, I made it blank...which I know is not a good idea, but I am kinda stuck here!

Thanks
Kumar
#3

[eluser]Michael Ekoka[/eluser]
hey Kumar,

at line 408 of the Router.php file, the different segments of your url are matched against the permitted uri characters entered in the config file.

That little routine uses a combination of the preg_match() and preg_quote() functions. preg_quote is supposed to escape the special regular expression characters like \ : . | etc, prior to sending them to preg_match. Now, my guess is that when you tried to add your single quote to the list of permitted characters in the config file, you simply appended it to the list, resulting in something like this:
Code:
"a-z 0-9~%.:_-'"
The problem with this is that the dash (-) is not part of the list of special characters escapable by preg_quote().
So the resulting escaped string submitted to preg_match will look like this:
Code:
"a-z 0-9~%\.\:_-'"
Now, notice that after the preg_quote operation, this entire string will be surrounded by brackets inside preg_match:
Code:
preg_match("|^[a-z 0-9~%\.\:_-']+$|i", $str))

The result is that the dash will not be evaluated as a character, but rather as if marking a range. Therefore, preg_match will try to match all characters in the range between a and z [a-z], 0 and 9 [0-9] AND FINALLY between the underscore and the single quote [_-'], this latter attempt is what's causing the error.

To fix, you need to add characters before the dash in your config file:
Code:
"a-z 0-9~%.:_'-"


Or if you choose to hack your CI installation a little bit:
- modify the permitted char entry in the config to manually escape the dash:
Code:
$config['permitted_uri_chars'] = '\-'.preg_quote('a-z 0-9~%.:_+=');
- then in the Router.php file replace the current snippet of code at line 408:
Code:
if ( ! preg_match("|^[".preg_quote($this->config->item('permitted_uri_chars'))."]+$|i", $str))
by this one which removes the preg_quote:
Code:
if ( ! preg_match("|^[".$this->config->item('permitted_uri_chars')."]+$|i", $str))

If you choose the latter path, make sure to document your changes, in your Router.php file and your config file. But, personally I would modify the core files only if I have no other option. So I would rather recommend the first solution.

Good luck.
#4

[eluser]unosoft[/eluser]
Thank you. I tried your first approach and it worked like a charm!

Kumar




Theme © iAndrew 2016 - Forum software by © MyBB