Hello I have a concern about mvc routing wildcard.
I am trying to use a route as in default route zf1 as follows:
website.com/controller/action/param1/value1/..../paramn/valuen/
It is fine using the below described routes without the trailing slash. But
when the trailing slash is added it does not matches a route. The description
of the route as follows (i try to describe this way instead of all array
elements):
route:
0. segment: /[:controller[/:action]]
child routes:
0. wildcard
child routes:
0. literal: '/'
So I thought adding the literal '/' child route to the wildcard child route may
cause it to match one but it did not. However it did solved the same trailing
slash problem when used as a child route after segment:
/[:controller[/:action]] route
0. segment: /[:controller[/:action]]
child routes:
0. literal '/'
Above settings solved the problem of trailing slash in the below address:
website.com/controller/action/
Then I have checked the source code and find out that it is the below code at
Zend\Mvc\Router\Http\Wildcard.php on line 123 within the match method (ZF
version: 2.2.5) that causes the problem:
L121 $params = explode('/', $path);
L122
L123 if (count($params) > 1 && ($params[0] !== '' || end($params) === '')) {
L124 return null;
L125 }
It explodes the path with the '/', and since the last $params element is '', it
returns null. Since the wildcard route does not accepts any of the valid
$params and the valid route, the wildcard route is cancelled before it can
check the child routes which is the literal '/' in this case.
If i remove the
|| end($params) === ''
part on line 123 at above code the app seems to work good.
Please tell me if this is a bug or should it be in that way to work properly.
And if this is a bug, will this be fixed with next update.
Thanks in advance,
Mucahit Sancar Kahveci
mobile:(Turkey) +90 532 311 35 71
email: [email protected]