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 8639772

Browse filesBrowse files
committed
bug #47932 Throw LogicException instead of Error when trying to generate logout-… (addiks)
This PR was merged into the 4.4 branch. Discussion ---------- Throw LogicException instead of Error when trying to generate logout-… …URL without request | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | N/A | License | MIT | Doc PR | N/A Currently the LogoutUrlGenerator will raise an Error if called without a current request present because it does not check if there is a request present before using it. The error that is raised is: `Call to a member function getBaseUrl() on null` on line 110 (line 114 with this patch applied) In my use-case, this get's called by `Symfony\Bundle\SecurityBundle\DataCollector\SecurityDataCollector::collect()` using the following code: ```php $logoutUrl = null; try { if (null !== $this->logoutUrlGenerator && !$token instanceof AnonymousToken) { $logoutUrl = $this->logoutUrlGenerator->getLogoutPath(); } } catch (\Exception $e) { // fail silently when the logout URL cannot be generated } ``` The above code inside the `SecurityDataCollector` tries to "fail silently" if no logout-URL cannot be generated. But this silent-fail fails itself because the thrown "exception" is not an `\Exception`, but an `\Error` instead (`\Error` is not an descendant of `\Exception`, so it does not get catched here). In order to resolve this situation, the proposed patch makes the LogoutUrlGenerator explicitly test if a request is actually present and then throw a `\LogicException` instead of an `\Error` if that check fails. Commits ------- 2ab4744 Throw LogicException instead of Error when trying to generate logout-URL without request
2 parents dffff8e + 2ab4744 commit 8639772
Copy full SHA for 8639772

File tree

Expand file treeCollapse file tree

1 file changed

+4
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+4
-0
lines changed

‎src/Symfony/Component/Security/Http/Logout/LogoutUrlGenerator.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Security/Http/Logout/LogoutUrlGenerator.php
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ private function generateLogoutUrl(?string $key, int $referenceType): string
107107

108108
$request = $this->requestStack->getCurrentRequest();
109109

110+
if (!$request) {
111+
throw new \LogicException('Unable to generate the logout URL without a Request.');
112+
}
113+
110114
$url = UrlGeneratorInterface::ABSOLUTE_URL === $referenceType ? $request->getUriForPath($logoutPath) : $request->getBaseUrl().$logoutPath;
111115

112116
if (!empty($parameters)) {

0 commit comments

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