zend-router
zend-router copied to clipboard
Wildcard no longer works when route ends on slash
One can reproduce this using:
$request = new \Zend\Http\Request;
$request->setUri('http://www.test.nl/bla/');
$route = \Zend\Router\Http\Wildcard::factory([]);
$match = $route->match($request);
// Now `$match === null`
Was introduced in https://github.com/zendframework/zend-router/pull/47 by @weierophinney
Excuse me; I think this bug was not recently introduced. But matches existing behaviour.
As this will be deprecated; feel free to close.
I'll roll my own wildcard implementation for now that simply consumes the remainder of the path.
Reference for anybody looking for something like what I described:
class MatchEverything implements RouteInterface
{
/** @var array */
private $defaults;
public function __construct(array $defaults)
{
$this->defaults = $defaults;
}
public function getAssembledParams()
{
return [];
}
public static function factory($options = [])
{
return new self($options['defaults'] ?? []);
}
public function match(Request $request, $pathOffset = null)
{
if (!method_exists($request, 'getUri')) {
return null;
}
$remainder = substr($request->getUri()->getPath(), $pathOffset);
return new RouteMatch($this->defaults, strlen($remainder));
}
public function assemble(array $params = [], array $options = [])
{
return '';
}
}
This repository has been closed and moved to laminas/laminas-router; a new issue has been opened at https://github.com/laminas/laminas-router/issues/4.