8000 Revert "merged branch Tobion/uselessparamdefaults (PR #5400)" · richardudovich/symfony@fdf2528 · GitHub
[go: up one dir, main page]

Skip to content

Commit fdf2528

Browse files
committed
Revert "merged branch Tobion/uselessparamdefaults (PR symfony#5400)"
This reverts commit 0f61b2e, reversing changes made to 5e7723f.
1 parent 1dd1532 commit fdf2528

File tree

3 files changed

+8
-29
lines changed

3 files changed

+8
-29
lines changed

src/Symfony/Component/Routing/RouteCompiler.php

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ class RouteCompiler implements RouteCompilerInterface
2323
/**
2424
* {@inheritDoc}
2525
*
26-
* @throws \LogicException If a variable is referenced more than once or if a required variable
27-
* has a default value that doesn't meet its own requirement.
26+
* @throws \LogicException If a variable is referenced more than once
2827
*/
2928
public function compile(Route $route)
3029
{
@@ -68,23 +67,14 @@ public function compile(Route $route)
6867
$tokens[] = array('text', substr($pattern, $pos));
6968
}
7069

71-
// find the first optional token and validate the default values for non-optional variables
72-
$optional = true;
70+
// find the first optional token
7371
$firstOptional = INF;
7472
for ($i = count($tokens) - 1; $i >= 0; $i--) {
7573
$token = $tokens[$i];
7674
if ('variable' === $token[0] && $route->hasDefault($token[3])) {
77-
if ($optional) {
78-
$firstOptional = $i;
79-
} elseif (!preg_match('#^'.$token[2].'$#', $route->getDefault($token[3]))) {
80-
throw new \LogicException(sprintf('The default value "%s" of the required variable "%s" in pattern "%s" does not match the requirement "%s". ' .
81-
'This route definition makes no sense because this default can neither be used as default for generating URLs nor can it ever be returned by the matching process. ' .
82-
'You should change the default to something that meets the requirement or remove it.',
83-
$route->getDefault($token[3]), $token[3], $route->getPattern(), $token[2]
84-
));
85-
}
75+
$firstOptional = $i;
8676
} else {
87-
$optional = false;
77+
break;
8878
}
8979
}
9080

src/Symfony/Component/Routing/Tests/Generator/UrlGeneratorTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,13 @@ public function testRelativeUrlWithNullParameter()
7575
}
7676

7777
/**
78-
* @expectedException \LogicException
78+
* @expectedException Symfony\Component\Routing\Exception\InvalidParameterException
7979
*/
8080
public function testRelativeUrlWithNullParameterButNotOptional()
8181
{
8282
$routes = $this->getRoutes('test', new Route('/testing/{foo}/bar', array('foo' => null)));
83-
// It should raise an exception when compiling this route because the given default value is absolutely
84-
// irrelevant for both matching and generating URLs.
83+
// This must raise an exception because the default requirement for "foo" is "[^/]+" which is not met with these params.
84+
// Generating path "/testing//bar" would be wrong as matching this route would fail.
8585
$this->getGenerator($routes)->generate('test', array(), false);
8686
}
8787

src/Symfony/Component/Routing/Tests/RouteCompilerTest.php

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -131,17 +131,6 @@ public function testRouteWithSameVariableTwice()
131131
{
132132
$route = new Route('/{name}/{name}');
133133

134-
$route->compile();
135-
}
136-
137-
/**
138-
* @expectedException \LogicException
139-
*/
140-
public function testRouteWithRequiredVariableAndBadDefault()
141-
{
142-
$route = new Route('/{foo}/', array('foo' => null));
143-
// It should raise an exception when compiling this route because the given default value is absolutely
144-
// irrelevant for both matching and generating URLs.
145-
$route->compile();
134+
$compiled = $route->compile();
146135
}
147136
}

0 commit comments

Comments
 (0)
0