ZF-9222: Zend_Rest_Route also routes non-REST URIs

Issue Type: Bug Created: 2010-02-21T08:11:33.000+0000 Last Updated: 2012-11-20T21:37:59.000+0000 Status: Open Fix version(s): Reporter: Moritz Mertinkat (maurice) Assignee: None Tags: - Zend_Rest_Route

Related issues: Attachments: - route-fix-zf-9222.patch


When Zend_Rest_Route is used as an additional route (see below) it also matches URIs that are not registered as responders. To be clear: It does not set the REST actions but the route's match() method returns true.

In most cases this will not lead to any errors because Zend_Rest_Route behaves just like Zend_Controller_Router_Route_Module (which is extends), but as soon as you're relying on automatic URL building using the ::assemble method from the current route you might end up with the wrong URL.


<pre class="highlight"> 
$router = $front_controller->getRouter();
$router->addRoute('rest', new Zend_Rest_Route($front_controller, array(), array('api' => array('product'))));

<pre class="literal">
URI                            Route matched
/                              ===> rest (ERROR)
/index                         ===> default (OK)
/index/index                   ===> default (OK)
/?a=1&b=2                      ===> rest (ERROR)
/index?a=1&b=2                 ===> default (OK)
/index/?a=1&b=2                ===> default (OK)
/api/supplier                  ===> default (OK)
/api/supplier/2                ===> default (OK)
/api/product                   ===> rest (OK)
/api/product/                  ===> rest (OK)
/api/product/1337              ===> rest (OK)
/api/product/?supplier=2       ===> rest (OK)

The problem occurs within the last lines in Zend_Rest_Route::match (btw, there should be some braces after the 'if' statement according to the coding guidelines):

<pre class="highlight">
$this->_values = $values + $params;

$result = $this->_values + $this->_defaults;

if ($partial && $result)

return $result;

These lines should be executed only if $path (from line 137) is not empty or $this->_allRestful() is true. Otherwise Zend_Rest_Route should return false.


Posted by Moritz Mertinkat (maurice) on 2010-02-21T11:08:09.000+0000

Zend_Rest_Route patch against 1.10.1

Posted by Moritz Mertinkat (maurice) on 2010-02-21T11:28:47.000+0000

Just noticed that Zend_Rest_Route does not work on "/" URIs (even though it accidentally matched them). Is this intentional?

curl -X POST -d "a=1&b=2" "" does not trigger the postAction of IndexController.

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.