merged branch merk/routing-bug (PR #4823)

Commits
-------

c061c30 Router#resolveString should return null instead of empty string when $value is null
a1d1a02 Null default value route regression

Discussion
----------

[Router] Null default value route regression

Bug fix: yes
Feature addition: no
Backwards compatibility break: no
Symfony2 tests pass: yes
Fixes the following tickets: #4823
Todo:
License of the code: MIT
Documentation PR:

---

The commit by @vicb 0555913fbb introduces a regression in the handling of default values that are null, while there are requirements still set for this value.

This is a failing test case and fix for the issue.

---------------------------------------------------------------------------

by merk at 2012-07-10T04:24:40Z

Now contains a fix, tests now pass.
This commit is contained in:
Fabien Potencier 2012-07-10 08:50:31 +02:00
commit f2958b3fb6
2 changed files with 17 additions and 0 deletions

View File

@ -114,6 +114,10 @@ class Router extends BaseRouter implements WarmableInterface
{
$container = $this->container;
if (null === $value) {
return null;
}
$escapedValue = preg_replace_callback('/%%|%([^%\s]+)%/', function ($match) use ($container, $value) {
// skip %%
if (!isset($match[1])) {

View File

@ -144,6 +144,19 @@ class RoutingTest extends \PHPUnit_Framework_TestCase
$router->getRouteCollection()->get('foo');
}
public function testDefaultValueNullAsEmptyStringRegression()
{
$routes = new RouteCollection();
$routes->add('foo', new Route('foo', array('foo' => null), array('foo' => '\d+')));
$sc = $this->getServiceContainer($routes);
$router = new Router($sc, 'foo');
$route = $router->getRouteCollection()->get('foo');
$this->assertNull($route->getDefault('foo'));
}
private function getServiceContainer(RouteCollection $routes)
{
$loader = $this->getMock('Symfony\Component\Config\Loader\LoaderInterface');