Permalink
Browse files

Closes #3778

Also closes #3711
Also closes #3652
Also closes #3636

Merge branch 'weierophinney-hotfix/3711'
  • Loading branch information...
2 parents 3629086 + 36600fd commit a3df97c5b07736e8ae40942ff9c68af4de77d0f4 @ralphschindler ralphschindler committed Feb 19, 2013
Showing with 108 additions and 3 deletions.
  1. +20 −2 library/Zend/Mvc/Router/Http/Part.php
  2. +88 −1 tests/ZendTest/Mvc/Router/Http/PartTest.php
@@ -136,8 +136,11 @@ public function match(Request $request, $pathOffset = null)
$uri = $request->getUri();
$pathLength = strlen($uri->getPath());
- if ($this->mayTerminate && $nextOffset === $pathLength && trim($uri->getQuery()) == "") {
- return $match;
+ if ($this->mayTerminate && $nextOffset === $pathLength) {
+ $query = $uri->getQuery();
+ if ('' == trim($query) || !$this->hasQueryChild()) {
+ return $match;
+ }
}
foreach ($this->routes as $name => $route) {
@@ -200,4 +203,19 @@ public function getAssembledParams()
// don't have to return anything here.
return array();
}
+
+ /**
+ * Is one of the child routes a query route?
+ *
+ * @return bool
+ */
+ protected function hasQueryChild()
+ {
+ foreach ($this->routes as $route) {
+ if ($route instanceof Query) {
+ return true;
+ }
+ }
+ return false;
+ }
}
@@ -13,9 +13,10 @@
use ArrayObject;
use PHPUnit_Framework_TestCase as TestCase;
use Zend\Http\Request as Request;
-use Zend\Stdlib\Request as BaseRequest;
use Zend\Mvc\Router\RoutePluginManager;
use Zend\Mvc\Router\Http\Part;
+use Zend\Stdlib\Parameters;
+use Zend\Stdlib\Request as BaseRequest;
use ZendTest\Mvc\Router\FactoryTester;
class PartTest extends TestCase
@@ -382,4 +383,90 @@ public function testFactoryShouldAcceptTraversableChildRoutes()
$route = Part::factory($options);
$this->assertInstanceOf('Zend\Mvc\Router\Http\Part', $route);
}
+
+ /**
+ * @group 3711
+ */
+ public function testPartRouteMarkedAsMayTerminateCanMatchWhenQueryStringPresent()
+ {
+ $options = array(
+ 'route' => array(
+ 'type' => 'Zend\Mvc\Router\Http\Literal',
+ 'options' => array(
+ 'route' => '/resource',
+ 'defaults' => array(
+ 'controller' => 'ResourceController',
+ 'action' => 'resource',
+ ),
+ ),
+ ),
+ 'route_plugins' => new RoutePluginManager(),
+ 'may_terminate' => true,
+ 'child_routes' => array(
+ 'child' => array(
+ 'type' => 'Zend\Mvc\Router\Http\Literal',
+ 'options' => array(
+ 'route' => '/child',
+ 'defaults' => array(
+ 'action' => 'child',
+ ),
+ ),
+ ),
+ ),
+ );
+
+ $route = Part::factory($options);
+ $request = new Request();
+ $request->setUri('http://example.com/resource?foo=bar');
+ $query = new Parameters(array('foo' => 'bar'));
+ $request->setQuery($query);
+ $query = $request->getQuery();
+
+ $match = $route->match($request);
+ $this->assertInstanceOf('Zend\Mvc\Router\RouteMatch', $match);
+ $this->assertEquals('resource', $match->getParam('action'));
+ }
+
+ /**
+ * @group 3711
+ */
+ public function testPartRouteMarkedAsMayTerminateButWithQueryRouteChildWillMatchChildRoute()
+ {
+ $options = array(
+ 'route' => array(
+ 'type' => 'Zend\Mvc\Router\Http\Literal',
+ 'options' => array(
+ 'route' => '/resource',
+ 'defaults' => array(
+ 'controller' => 'ResourceController',
+ 'action' => 'resource',
+ ),
+ ),
+ ),
+ 'route_plugins' => new RoutePluginManager(),
+ 'may_terminate' => true,
+ 'child_routes' => array(
+ 'query' => array(
+ 'type' => 'Zend\Mvc\Router\Http\Query',
+ 'options' => array(
+ 'defaults' => array(
+ 'query' => 'string',
+ ),
+ ),
+ ),
+ ),
+ );
+
+ $route = Part::factory($options);
+ $request = new Request();
+ $request->setUri('http://example.com/resource?foo=bar');
+ $query = new Parameters(array('foo' => 'bar'));
+ $request->setQuery($query);
+ $query = $request->getQuery();
+
+ $match = $route->match($request);
+ $this->assertInstanceOf('Zend\Mvc\Router\RouteMatch', $match);
+ $this->assertEquals('string', $match->getParam('query'));
+ $this->assertEquals('bar', $match->getParam('foo'));
+ }
}

0 comments on commit a3df97c

Please sign in to comment.