Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 516fa6b

Browse filesBrowse files
author
Emmanuel BORGES
committed
[FrameworkBundle] Fix UrlGenerator::generate to return an empty string instead of null
1 parent 6654a41 commit 516fa6b
Copy full SHA for 516fa6b

File tree

3 files changed

+6
-6
lines changed
Filter options

3 files changed

+6
-6
lines changed

‎src/Symfony/Component/Routing/Generator/ConfigurableRequirementsInterface.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Routing/Generator/ConfigurableRequirementsInterface.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* The possible configurations and use-cases:
2121
* - setStrictRequirements(true): Throw an exception for mismatching requirements. This
2222
* is mostly useful in development environment.
23-
* - setStrictRequirements(false): Don't throw an exception but return null as URL for
23+
* - setStrictRequirements(false): Don't throw an exception but return an empty string as URL for
2424
* mismatching requirements and log the problem. Useful when you cannot control all
2525
* params because they come from third party libs but don't want to have a 404 in
2626
* production environment. It should log the mismatch so one can review it.

‎src/Symfony/Component/Routing/Generator/UrlGenerator.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Routing/Generator/UrlGenerator.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ protected function doGenerate($variables, $defaults, $requirements, $tokens, $pa
171171
$this->logger->error($message, ['parameter' => $varName, 'route' => $name, 'expected' => $token[2], 'given' => $mergedParams[$varName]]);
172172
}
173173

174-
return;
174+
return '';
175175
}
176176

177177
$url = $token[1].$mergedParams[$varName].$url;
@@ -226,7 +226,7 @@ protected function doGenerate($variables, $defaults, $requirements, $tokens, $pa
226226
$this->logger->error($message, ['parameter' => $token[3], 'route' => $name, 'expected' => $token[2], 'given' => $mergedParams[$token[3]]]);
227227
}
228228

229-
return;
229+
return '';
230230
}
231231

232232
$routeHost = $token[1].$mergedParams[$token[3]].$routeHost;

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Routing/Tests/Generator/UrlGeneratorTest.php
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ public function testGenerateForRouteWithInvalidOptionalParameterNonStrict()
203203
$routes = $this->getRoutes('test', new Route('/testing/{foo}', ['foo' => '1'], ['foo' => 'd+']));
204204
$generator = $this->getGenerator($routes);
205205
$generator->setStrictRequirements(false);
206-
$this->assertNull($generator->generate('test', ['foo' => 'bar'], UrlGeneratorInterface::ABSOLUTE_URL));
206+
$this->assertSame('', $generator->generate('test', ['foo' => 'bar'], UrlGeneratorInterface::ABSOLUTE_URL));
207207
}
208208

209209
public function testGenerateForRouteWithInvalidOptionalParameterNonStrictWithLogger()
@@ -214,7 +214,7 @@ public function testGenerateForRouteWithInvalidOptionalParameterNonStrictWithLog
214214
->method('error');
215215
$generator = $this->getGenerator($routes, [], $logger);
216216
$generator->setStrictRequirements(false);
217-
$this->assertNull($generator->generate('test', ['foo' => 'bar'], UrlGeneratorInterface::ABSOLUTE_URL));
217+
$this->assertSame('', $generator->generate('test', ['foo' => 'bar'], UrlGeneratorInterface::ABSOLUTE_URL));
218218
}
219219

220220
public function testGenerateForRouteWithInvalidParameterButDisabledRequirementsCheck()
@@ -489,7 +489,7 @@ public function testUrlWithInvalidParameterInHostInNonStrictMode()
489489
$routes = $this->getRoutes('test', new Route('/', [], ['foo' => 'bar'], [], '{foo}.example.com'));
490490
$generator = $this->getGenerator($routes);
491491
$generator->setStrictRequirements(false);
492-
$this->assertNull($generator->generate('test', ['foo' => 'baz'], UrlGeneratorInterface::ABSOLUTE_PATH));
492+
$this->assertSame('', $generator->generate('test', ['foo' => 'baz'], UrlGeneratorInterface::ABSOLUTE_PATH));
493493
}
494494

495495
public function testHostIsCaseInsensitive()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.