-
Notifications
You must be signed in to change notification settings - Fork 201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix missing isRouted and access check #1305
Fix missing isRouted and access check #1305
Conversation
if ($this->redirectRepository && $redirect = $this->redirectRepository->findMatchingRedirect($path, [])) { | ||
/** @var \Drupal\redirect\Entity\Redirect|null $redirect */ | ||
$redirect = $this->redirectRepository->findMatchingRedirect($path, []); | ||
if ($redirect) { | ||
return $redirect->getRedirectUrl(); | ||
} | ||
$url = $redirect->getRedirectUrl(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This breaks the type annotation on line 99. The @var
annotation is not needed for getRedirectUrl
.
Is it possible to take the $redirect =
out of the if
statement for legibility?
I've opened https://www.drupal.org/project/redirect/issues/3309603 to handle the return type annotation that's incorrect for findMatchingRedirect
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can take out $redirect =
but that gets otherwise ugly. Would you prefer something like this?
if ($this->redirectRepository) {
$redirect = $this->redirectRepository->findMatchingRedirect($path, []);
if ($redirect){
$url = $redirect->getRedirectUrl();
}
}
if(empty($url)) {
$url = $this->pathValidator->getUrlIfValidWithoutAccessCheck($path);
}
if ($url && $url->isRouted() && $url->access()) {
return $url;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe something along the lines of this is better
if ($this->redirectRepository) {
$redirect = $this->redirectRepository->findMatchingRedirect($path, []);
}
if (!empty($redirect)){
$url = $redirect->getRedirectUrl();
}
else {
$url = $this->pathValidator->getUrlIfValidWithoutAccessCheck($path);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a ternary may be okay, I also tend to avoid empty
checks if possible.
<?php
$redirect = $this->redirectRepository ? $this->redirectRepository->findMatchingRedirect($path, []) : NULL;
if ($redirect !== NULL) {
$url = $redirect->getRedirectUrl();
}
else {
$url = $this->pathValidator->getUrlIfValidWithoutAccessCheck($path);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
When redirect paths are resolved with the route_load data producer, the isRouted() and access() checks are not validated.
This leads to problems, when route_loud is called for a redirect to an external url. They should not resolve to anything.
Fixes #1306