ZF-2301: Zend_Controller_Router_Route_Regex::assemble() uses default even when parameter is matched

Issue Type: Bug Created: 2007-12-12T16:28:30.000+0000 Last Updated: 2008-03-21T16:25:43.000+0000 Status: Resolved Fix version(s): - 1.5.0 (17/Mar/08)

Reporter: Chris Abernethy (brownoxford) Assignee: Ralph Schindler (ralph) Tags: - Zend_Controller

Related issues: - ZF-2482

Attachments: - martel-regex-route-issue-ZF-2301.patch


It seems like default values are being used even when parameters are actually matched from the url. Take the following for example:

<pre class="highlight">
$route = new Zend_Controller_Router_Route_Regex(
, array('page' => 1) // Defaults
, array(1 => 'page') // Parameter map
, 'itemlist/%d'

$values = $route->match('/itemlist/2');


$url = $route->assemble();

// Expect string(10) "itemlist/2"

$url = $route->assemble(array('page' => 2));

// Expect string(10) "itemlist/2"

Which results in:

<pre class="literal">
array(1) {
  string(1) "2"
string(10) "itemlist/1"
string(10) "itemlist/2"

This appears to work fine if the parameter map is reversed so that 'page' is the key and '1' is the value.


Posted by Michal Minicki (martel) on 2008-01-11T08:17:42.000+0000

Good catch, Chris. It may be tricky to get straight, though.

As you already see, ZF supports declaring parameter names in both ways. I would like to keep it that way but I'm afraid we will have to do some magic from the looks of it.

If you already have some working code, then please go ahead and share.

Posted by Ralph Schindler (ralph) on 2008-02-28T12:07:15.000+0000

Hey Martel,

I think I've found the issue (it has to do with the way that assemble() merges data from defaults, values and provided data).

If this patch works for you, can I go ahead and commit?

Thanks, Ralph

Posted by Michal Minicki (martel) on 2008-02-28T13:22:34.000+0000

Looks very good, Ralph. Go ahead and commit. Thanks.

But for the sake of my conscience, please change the last lines of the test. This:

<pre class="highlight">
+        // check to make sure that the assembly will return with provided page=2 in the correct place
+        $this->assertEquals('itemlist/2', $route->assemble(array('page' => 2)));

Should be changed into this:

<pre class="highlight">
+        // check to make sure that the assembly will return with provided page=2 in the correct place
+        $this->assertEquals('itemlist/3', $route->assemble(array('page' => 3)));
+        // check to make sure that the assembly can reset a single parameter
+        $this->assertEquals('itemlist/1', $route->assemble(array('page' => null)));

First to make sure we don't get a 2 out of URL values, second to make sure parameter is being reset back to default.

Posted by Ralph Schindler (ralph) on 2008-02-29T12:58:05.000+0000

fixed in r8470

Keeping open until its merged into 1.5.0 branch.

Posted by Ralph Schindler (ralph) on 2008-02-29T13:46:35.000+0000

FIxed in both the 1.5 branch as well as trunk

Have you found an issue?

See the Overview section for more details.


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

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