Commit 1a01a33a authored by alexpott's avatar alexpott

Issue #2708629 by tim.plunkett:...

Issue #2708629 by tim.plunkett: \Drupal\system\Plugin\Condition\RequestPath::evaluate() fails if the current path is '/'
parent 9ba21594
......@@ -147,7 +147,9 @@ public function evaluate() {
$request = $this->requestStack->getCurrentRequest();
// Compare the lowercase path alias (if any) and internal path.
$path = rtrim($this->currentPath->getPath($request), '/');
$path = $this->currentPath->getPath($request);
// Do not trim a trailing slash if that is the complete path.
$path = $path === '/' ? $path : rtrim($path, '/');
$path_alias = Unicode::strtolower($this->aliasManager->getAliasByPath($path));
return $this->pathMatcher->matchPath($path_alias, $pages) || (($path != $path_alias) && $this->pathMatcher->matchPath($path, $pages));
......
......@@ -127,5 +127,14 @@ public function testConditions() {
$this->assertFalse($condition->evaluate(), 'The system_path /my/pass/page4 fails for a missing path.');
// Test a path of '/'.
$this->aliasManager->addAlias('/', '/my/pass/page3');
$this->currentPath->setPath('/', $request);
$this->requestStack->pop();
$this->requestStack->push($request);
$this->assertTrue($condition->evaluate(), 'The system_path my/pass/page3 passes for wildcard paths.');
$this->assertEqual($condition->summary(), 'Return true on the following pages: /my/pass/*', 'The condition summary matches for a wildcard path');
}
}
......@@ -76,6 +76,10 @@ public function getPathByAlias($alias, $langcode = NULL) {
* @return
*/
public function getAliasByPath($path, $langcode = NULL) {
if ($path[0] !== '/') {
throw new \InvalidArgumentException(sprintf('Source path %s has to start with a slash.', $path));
}
$langcode = $langcode ?: $this->defaultLanguage;
$this->lookedUp[$path] = 1;
return $this->aliases[$path][$langcode];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment