permitted_uri_chars single quote - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: permitted_uri_chars single quote (/showthread.php?tid=1721) |
permitted_uri_chars single quote - El Forum - 06-22-2007 [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 permitted_uri_chars single quote - El Forum - 07-01-2007 [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 permitted_uri_chars single quote - El Forum - 07-02-2007 [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~%.:_-'" So the resulting escaped string submitted to preg_match will look like this: Code: "a-z 0-9~%\.\:_-'" 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~%.:_+='); Code: if ( ! preg_match("|^[".preg_quote($this->config->item('permitted_uri_chars'))."]+$|i", $str)) 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. permitted_uri_chars single quote - El Forum - 07-02-2007 [eluser]unosoft[/eluser] Thank you. I tried your first approach and it worked like a charm! Kumar |