ZF-6654: Chaining routes with wildcard (*) does not work

Issue Type: Bug Created: 2009-05-14T08:29:31.000+0000 Last Updated: 2009-12-17T17:41:41.000+0000 Status: Resolved Fix version(s): - 1.10.0 (27/Jan/10)

Reporter: Andrei Nikolov (viperx) Assignee: Ben Scholzen (dasprid) Tags: - Zend_Controller

Related issues: - ZF-8515



Reproduce code:

<pre class="highlight">
$userRoute = new Zend_Controller_Router_Route_Hostname(':nickname..'.$configuration->general->domain,
                    array('controller'=>'profile', 'action'=>'view'));

$userActionsRoute = new  Zend_Controller_Router_Route(':action/*',
$router->addRoute('uActionsRoute', $userRoute->chain($userActionsRoute));

This have the simple purpose to have URLs like:*, for example

but in ZF 1.8.1 the above route 'uActionsRoute' does not match such URLs. This is because in Controller/Router/Route.php there is a bug in match() method - when matching wildcard variables, $matchedPath is not updated.

Proposed fix:

<pre class="highlight">
                // Path is longer than a route, it's not a match
                if (!array_key_exists($pos, $this->_parts)) {
                    if ($partial) {
                    } else {
                        return false;
                // If it's a wildcard, get the rest of URL as wildcard data and stop matching
                if ($this->_parts[$pos] == '*') {
                    $count = count($path);
                    for($i = $pos; $i < $count; $i+=2) {
                        $var = urldecode($path[$i]);                        
                        //start fix:
                        $matchedPath .= $path[$i] . $this->_urlDelimiter;
                        if (isset ($path[$i+1]))
                            $matchedPath .= $path[$i+1] . $this->_urlDelimiter;
                        //end fix

                        if (!isset($this->_wildcardData[$var]) && !isset($this->_defaults[$var]) && !isset($values[$var])) {
                            $this->_wildcardData[$var] = (isset($path[$i+1])) ? urldecode($path[$i+1]) : null;

                //fix: moved this after the above IF block
                $matchedPath .= $pathPart . $this->_urlDelimiter;
                //end fix

                $name     = isset($this->_variables[$pos]) ? $this->_variables[$pos] : null;
                $pathPart = urldecode($pathPart);
// and so on...


Posted by Matthew Weier O'Phinney (matthew) on 2009-05-14T09:15:38.000+0000

Assigning to Ben to triage.

Posted by Andrei Nikolov (viperx) on 2009-05-15T04:09:44.000+0000

Sorry, wrong fix.. here is fix of the fix :)

//start fix: $matchedPath .= $path[$i] . $this->_urlDelimiter; if (isset ($path[$i+1])) { $matchedPath .= $path[$i+1] . $this->_urlDelimiter; } //end fix

Posted by Andrei Nikolov (viperx) on 2009-07-20T15:16:17.000+0000

Whats going on with this issue? Reported 2 months ago, provided you with the patch code, and still not fixed.. This is just not serious attention..

Posted by Marc van de Geijn (bhosted) on 2009-07-22T04:45:30.000+0000

I ran into this issue also and it took me a day to find the problem. It would be very nice if this is fixed in the next release of the Framework.

Posted by Marc van de Geijn (bhosted) on 2009-07-22T04:52:58.000+0000

I checked, but this issue is still present in the 1.9 preview release.

Unfortunatly I'm not allowed to change the affected versions for this issue. Is it an option to clone this issue and change the affected version?

Posted by Marc van de Geijn (bhosted) on 2009-07-22T05:07:31.000+0000

Last comment from me on this issue. I've fixed it another way:

            // If it's a wildcard, get the rest of URL as wildcard data and stop matching
            if ($this->_parts[$pos] == '*') {
                $count = count($path);
                for($i = $pos; $i < $count; $i+=2) {
                    $var = urldecode($path[$i]);
                    if (!isset($this->_wildcardData[$var]) && !isset($this->_defaults[$var]) && !isset($values[$var])) {
                        $this->_wildcardData[$var] = (isset($path[$i+1])) ? urldecode($path[$i+1]) : null;
                $matchedPath = implode( $this->_urlDelimiter, $path );

I think it's safe to implode the $path array and assign it to $matchedPath, as the wildcard for loop is processing the full path.

Posted by Jason Webster (jasonistaken) on 2009-08-13T17:12:06.000+0000

Cleaned up formatting in report.

Posted by St├ęphane (stephane) on 2009-08-18T06:22:02.000+0000

Well, I also encountered this issue today and lost quite some time. Hopefully, the fix proposed by Andrei just did it. I hope this patch will make its way to the next minor release.

Posted by St├ęphane (stephane) on 2009-08-18T07:04:54.000+0000

Just a little update. I finally had to use Marc's fix as there was a variable scope issue with the one provided by Andrei. I am using ZF 1.9.1.

Posted by Michiel Thalen (chielsen) on 2009-10-12T20:58:29.000+0000

About time this gets fixed, very annoying this does not work and you are trying to figure out how the routing works.

Posted by Artur Bodera (joust) on 2009-10-13T10:57:39.000+0000

It is a close one to the one I've stumbled upon when using chains and ``'' (empty) static routes: ZF-7848

Posted by Jeroen Weustink (j.weustink) on 2009-10-20T06:13:51.000+0000

Just updated to 1.9.4 and issue still isn't fixed..?????

Posted by Kevin Young (kyoung) on 2009-10-28T13:58:18.000+0000

This issue still persists with 1.9.5.

Marc van de Geijn's fix solved the problem for me.

Posted by Marc van de Geijn (bhosted) on 2009-11-30T04:38:05.000+0000

This issue still persists with 1.9.6.

Posted by Sune Kibsgaard Pedersen (kibs) on 2009-12-10T05:04:02.000+0000

Will this be fixed in 1.9.7?

Posted by chaoshu sha ( on 2009-12-10T05:34:07.000+0000

this below maybe another fix,

Index: Route.php

--- Route.php (revision 1324) +++ Route.php (working copy) @@ -239,6 +239,7 @@ $var = urldecode($path[$i]); if (!isset($this->_wildcardData[$var]) && !isset($this->_defaults[$var]) && !isset($values[$var])) { $this->_wildcardData[$var] = (isset($path[$i+1])) ? urldecode($path[$i+1]) : null; + $matchedPath .= $this->_wildcardData[$var] . $this->_urlDelimiter; } } break;

Posted by Cristian Bichis (avantis) on 2009-12-17T08:33:43.000+0000

This doesn't seems to get fixed even now, on 1.9.7...

Lot of unfixed bugs on core ZF components :(

Posted by Andrei Nikolov (viperx) on 2009-12-17T08:45:22.000+0000

well, why fixing this bug, when we can just go and manually fix it every time when we upgrade ZF version.. really no need to fix it

Posted by Cristian Bichis (avantis) on 2009-12-17T09:31:41.000+0000

I have made my own route class based on your fix, but of course, this is also a problem at any Route.php update, we loose the updates to the match function...

Posted by Cristian Bichis (avantis) on 2009-12-17T09:46:48.000+0000

Actually i don't understand why there is planned a 2.0 release if doesn't seems to be 1.x branch usable without lot of manual fixes. I have quite lot of "fix" classes taken from the Jira, just to cleanup the bugs from framework...

I guess for a very small project - newbies like - is possible that you won't find any bugs, but even for small-medium projects is impossible to develop without tons of classes to fix the bugs...

Posted by Artur Bodera (joust) on 2009-12-17T11:29:03.000+0000

I concur. I've got a pack of diff/patches to fix the holes, but it's ridiculous.

For example, the bug reported by me (ZF-7848) and related to static routes has a test scenario taken directly from ZF documentation examples! So something that is given in docs as an example is broken dead.

What is even more puzzling is that I've already devised a fix and posted it here, but none cares to use it :-)

Have you found an issue?

See the Overview section for more details.


© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.