Problem/Motivation
While play with Traefik edge router redirectRegex middleware, accessing a Drupal 9.3.12 site from a redirection, and with a URL without trailing slash (https://www.domain.com), Drupal throw this exception:
Warning: Uninitialized string offset 0 in Drupal\path_alias\AliasManager->getAliasByPath() (line 184 of core/modules/path_alias/src/AliasManager.php).
Drupal\path_alias\AliasManager->getAliasByPath('') (Line: 154)
Drupal\system\Plugin\Condition\RequestPath->evaluate() (Line: 68)
Drupal\allow_iframed_site\EventSubscriber\RemoveXFrameOptionsSubscriber->RemoveXFrameOptions(Object, 'kernel.response', Object) (Line: 79)
Drupal\webprofiler\EventDispatcher\TraceableEventDispatcher->dispatch(Object, 'kernel.response') (Line: 191)
Symfony\Component\HttpKernel\HttpKernel->filterResponse(Object, Object, 1) (Line: 137)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 80)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 191)
Drupal\page_cache\StackMiddleware\PageCache->fetch(Object, 1, 1) (Line: 128)
Drupal\page_cache\StackMiddleware\PageCache->lookup(Object, 1, 1) (Line: 82)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 38)
Drupal\webprofiler\StackMiddleware\WebprofilerMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 708)
Drupal\Core\DrupalKernel->handle(Object) (Line: 85)
Steps to reproduce
Unknown, access to drupal without ending / to the https://www.domain.com ?
Proposed resolution
In AliasManager.php, line 183, replace:
public function getAliasByPath($path, $langcode = NULL) {
if ($path[0] !== '/') {
throw new \InvalidArgumentException(sprintf('Source path %s has to start with a slash.', $path));
}
by
public function getAliasByPath($path, $langcode = NULL) {
if ($path && $path[0] !== '/') {
throw new \InvalidArgumentException(sprintf('Source path %s has to start with a slash.', $path));
}
Release notes snippet
Fix AliasManager->getAliasByPath() handling of empty path string.