CodeIgniter Forums
dash not allowed in custom routed uri since 1.7? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: dash not allowed in custom routed uri since 1.7? (/thread-13668.html)



dash not allowed in custom routed uri since 1.7? - El Forum - 12-01-2008

[eluser]thenetmonkey[/eluser]
Hello,

I've just encountered a strange problem since upgrading from 163 to 170: the router isn't letting me use a - (dash) in my uri segments anymore.

The following route is setup in config/routes.php:
Code:
$route['feed/(:any)'] = '/feed/index/$1';

with this rule in place, the following URL used to work:
http://www.wineconsigners.com/feed/wine-searcher

Now, however, I get a 404 page thrown even before the constructor for my feed class is built ( I put a show_error( 'feed' ); in my feed constructor just after the parent::Controller(); call and I still get the 404 )

The URL works fine when I take the dash out, so I've just told my vendor to use the new feed URL of http://www.wineconsigners.com/feed/winesearcher and it's working fine.

I asked around on IRC and someone named [OES] suggested I try using this route:
Code:
$route['feed/(.*)'] = '/feed/index/$1';

and that regexp didn't work either.

My permitted_uri_chars looks like this:
Code:
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-\+';
this was the same permitted_uri_chars I used in 163 and it worked there.

I tried doing a diff between the 163 Router.php and 170 Router.php lib, but there are only a couple differences, and none of them look like they have anything to do with handling dashes, but I could be wrong.

I'm running PHP Version 4.3.10-22 on Apache 1.3.33.

Has anyone else ran into this when the upgraded to 170?
Is there a known fix?
Should I file a bug report?

Thanks in advance for your help.
Billy


dash not allowed in custom routed uri since 1.7? - El Forum - 12-02-2008

[eluser]sophistry[/eluser]
@thenetmonkey - welcome to CI.

unless you are using the latest SVN 1.7.1 version of CI disallowed characters would not give you a 404 (previous to this change disallowed chars just got you an exit(); with a string message - not even HTML).

anyhow, if you are not using SVN then your problem must be elsewhere.

what does your ruri segment look like? did you try echoing it?


dash not allowed in custom routed uri since 1.7? - El Forum - 12-02-2008

[eluser]thenetmonkey[/eluser]
@sohpistry - thanks

Nope, not using SVN, just normal 1.7.0 release. I'm accustomed to seeing the old string message when I use a non-permitted character, but that change you mention in the SVN 171 sounds nice.

I've only been using CI for about a month, so I'm still learning how the internals work.
I've tried doing this in my controller:

Code:
class Feed extends Controller {
  function Feed {
    parent::Controller();
    show_error( $this->uri->ruri_string() . "\n" . $this->uri->uri_string() );
  }

And this works fine if I don't have a dash in the uri, but if I do have a dash, all I get is the 404 page.

So where should I put the show_error statement so that it displays before the 404?


dash not allowed in custom routed uri since 1.7? - El Forum - 12-02-2008

[eluser]sophistry[/eluser]
how about in the show_404() function? it's in codeigniter/Common.php


dash not allowed in custom routed uri since 1.7? - El Forum - 12-02-2008

[eluser]thenetmonkey[/eluser]
Hmm... looks like I don't know how to access the uri contents at that point.

$this->uri->uri_string() and $this->uri->ruri_string() don't work in the show_404() function, I guess $this isn't defined?

I tried doing $ci =& get_instance(), but get_instance() isn't defined either at that point.

So, how should I echo the uri or ruri string?


dash not allowed in custom routed uri since 1.7? - El Forum - 12-02-2008

[eluser]sophistry[/eluser]
doh! that code must be bailing out early.

i would just follow the code execution - into the Router.php class i suppose.


dash not allowed in custom routed uri since 1.7? - El Forum - 12-02-2008

[eluser]Michael Wales[/eluser]
Try using Regex rather than the (:any) tag.

Code:
$route['feed/([A-Za-z0-9-_]+)'] = 'feed/index/$1';

I know for a fact that works - I do it all the time. Smile


dash not allowed in custom routed uri since 1.7? - El Forum - 12-02-2008

[eluser]thenetmonkey[/eluser]
I figured it out.

My permitted_uri_chars was messed up.

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

I changed it to:
Code:
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_+-';

The reason is the the uri->_filter_uri() function does this:
Code:
preg_match("|^[".preg_quote($this->config->item('permitted_uri_chars'))."]+$|i", $str))

preg_quote escapes all chars that have special regex meaning. I didn't know that, so I was trying to quote the chars myself. I'm not sure how my permitted_uri_chars was working on 163, or why it broke in 170 when a uri had a dash in it, but fixing the permitted_uri_chars string makes everything work now.

Thanks to everyone who helped out on this.