Skip to content
This repository was archived by the owner on Oct 2, 2019. It is now read-only.

Commit ee46e80

Browse files
committed
Merge pull request zendframework#545 from Bittarman/fix/chain-delimiter-stripping
Fixed path delimeters being stripped by chain routes affecting later routes
2 parents 4911fb4 + 50e9083 commit ee46e80

File tree

2 files changed

+70
-8
lines changed

2 files changed

+70
-8
lines changed

library/Zend/Controller/Router/Route/Chain.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ public function chain(Zend_Controller_Router_Route_Abstract $route, $separator =
8686
*/
8787
public function match($request, $partial = null)
8888
{
89+
$rawPath = $request->getPathInfo();
8990
$path = trim($request->getPathInfo(), self::URI_DELIMITER);
9091
$subPath = $path;
9192
$values = array();
@@ -100,6 +101,7 @@ public function match($request, $partial = null)
100101
$separator = substr($subPath, 0, strlen($this->_separators[$key]));
101102

102103
if ($separator !== $this->_separators[$key]) {
104+
$request->setPathInfo($rawPath);
103105
return false;
104106
}
105107

@@ -116,7 +118,7 @@ public function match($request, $partial = null)
116118
$res = $route->match($match, true);
117119

118120
if ($res === false) {
119-
$request->setPathInfo($path);
121+
$request->setPathInfo($rawPath);
120122
return false;
121123
}
122124

tests/Zend/Controller/Router/Route/ChainTest.php

Lines changed: 67 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,30 @@ public function testMultipleChainsWithVersion2Routes()
839839
$this->assertEquals('chain2', $rewrite->getCurrentRouteName(), 'Routing did not match expected route');
840840
}
841841

842+
/**
843+
* @throws Zend_Controller_Router_Exception
844+
*/
845+
public function testMultipleChainsResettingPathInfoInSegmentBlock()
846+
{
847+
$foo = new Zend_Controller_Router_Route_SubclassTest('notfoo');
848+
$bar = new Zend_Controller_Router_Route_SubclassTest('bar', array('baz' => 'no'));
849+
850+
851+
$chain = $foo->chain($bar);
852+
853+
$static = new Zend_Controller_Router_Route_SimpleSubclassTest('/foo', array('foo' => 'foo'));
854+
855+
$rewrite = new Zend_Controller_Router_Rewrite();
856+
$rewrite->addRoute('static', $static); // First In Last Out, we want this to be matched against second
857+
$rewrite->addRoute('chain', $chain);
858+
$request = new Zend_Controller_Router_ChainTest_Request('http://www.zend.com/foo');
859+
860+
$res = $rewrite->route($request);
861+
$this->assertEquals('foo', $res->getParam('foo'), 'Route did not match');
862+
$this->assertEquals('static', $rewrite->getCurrentRouteName(), 'Routing did not match expected route');
863+
864+
}
865+
842866
/**
843867
* @group ZF-11443
844868
*/
@@ -958,13 +982,53 @@ protected function _getRouter()
958982
}
959983
}
960984

985+
class Zend_Controller_Router_Route_SimpleSubclassTest extends Zend_Controller_Router_Route_Abstract
986+
{
987+
/**
988+
* @var string
989+
*/
990+
protected $path;
991+
992+
/**
993+
* @var array
994+
*/
995+
protected $params = array();
996+
997+
public function __construct($path, $params)
998+
{
999+
$this->path = $path;
1000+
$this->params = $params;
1001+
}
1002+
1003+
public function match($path, $partial = false)
1004+
{
1005+
$path = $path->getPathInfo();
1006+
if ($path == $this->path) {
1007+
$this->setMatchedPath($this->path);
1008+
return $this->params;
1009+
}
1010+
return false;
1011+
}
1012+
1013+
public function getVersion()
1014+
{
1015+
return 2;
1016+
}
1017+
1018+
public function assemble($data = array(), $reset = false, $encode = false)
1019+
{}
1020+
1021+
public static function getInstance(Zend_Config $config)
1022+
{}
1023+
1024+
}
9611025

9621026
class Zend_Controller_Router_Route_SubclassTest extends Zend_Controller_Router_Route_Static
9631027
{
9641028
public function match($path, $partial = false)
9651029
{
9661030
$path = $path->getPathInfo();
967-
$match = parent::match($path, $partial); // TODO: Change the autogenerated stub
1031+
$match = parent::match($path, $partial);
9681032
if (is_array($match)) {
9691033
$this->setMatchedPath($this->_route);
9701034
}
@@ -977,14 +1041,10 @@ public function getVersion()
9771041
}
9781042

9791043
public function assemble($data = array(), $reset = false, $encode = false)
980-
{
981-
// TODO: Implement assemble() method.
982-
}
1044+
{}
9831045

9841046
public static function getInstance(Zend_Config $config)
985-
{
986-
// TODO: Implement getInstance() method.
987-
}
1047+
{}
9881048

9891049
}
9901050

0 commit comments

Comments
 (0)