ZF-9222: Zend_Rest_Route also routes non-REST URIs

Description

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.

Sample:

 
$router = $front_controller->getRouter();
$router->addRoute('rest', new Zend_Rest_Route($front_controller, array(), array('api' => array('product'))));
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):


$this->_values = $values + $params;

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

if ($partial && $result)
    $this->setMatchedPath($request->getPathInfo());

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.

Comments

Zend_Rest_Route patch against 1.10.1

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" "http://api.mydomain.com/"}} does not trigger the {{postAction}} of {{IndexController}}.