diff --git a/Classes/MOC/Redirects/Routing/RedirectFrontendNodeRoutePartHandler.php b/Classes/MOC/Redirects/Routing/RedirectFrontendNodeRoutePartHandler.php index 55841f1..4bc4a62 100644 --- a/Classes/MOC/Redirects/Routing/RedirectFrontendNodeRoutePartHandler.php +++ b/Classes/MOC/Redirects/Routing/RedirectFrontendNodeRoutePartHandler.php @@ -35,24 +35,6 @@ protected function findValueToMatch($requestPath) return $requestPath; } - /** - * @param string $haystack - * @param string $needle - * @return bool - */ - protected function endsWith($haystack, $needle) { - return $needle === "" || (($temp = strlen($haystack) - strlen($needle)) >= 0 && strpos($haystack, $needle, $temp) !== FALSE); - } - - /** - * @param string $haystack - * @param string $needle - * @return bool - */ - protected function startsWith($haystack, $needle) { - return $needle === "" || strrpos($haystack, $needle, -strlen($haystack)) !== FALSE; - } - /** * @param string $requestPath * @return boolean TRUE if the $requestPath could be matched, otherwise FALSE @@ -62,9 +44,6 @@ protected function matchValue($requestPath) /** @var Uri $uri */ $uri = $this->bootstrap->getActiveRequestHandler()->getHttpRequest()->getUri(); $relativeUrl = rtrim($uri->getPath(), '/'); - if($this->startsWith($relativeUrl, '/')){ - $tempRelativeUrl = substr($relativeUrl, 1); - } $relativeUrlWithQueryString = $relativeUrl . ($uri->getQuery() ? '?' . $uri->getQuery() : ''); $absoluteUrl = $uri->getHost() . $relativeUrl; $absoluteUrlWithQueryString = $uri->getHost() . $relativeUrlWithQueryString; @@ -81,7 +60,8 @@ protected function matchValue($requestPath) ->where('n.workspace = :workspace') ->setParameter('workspace', 'live') ->andWhere('n.properties LIKE :relativeUrl') - ->setParameter('relativeUrl', '%"redirectUrl"%' . str_replace('/', '\\\\\\/', $tempRelativeUrl) . '%'); + ->setParameter('relativeUrl', '%"redirectUrl"%' . str_replace('/', '\\\\\\/', ltrim($relativeUrl, '/')) . '%'); + $query = $queryBuilder->getQuery(); $nodes = $query->getResult(); if (empty($nodes)) { @@ -91,27 +71,20 @@ protected function matchValue($requestPath) foreach ($nodes as $node) { /** @var NodeData $node */ // Prevent partial matches - $redirectUrl = preg_replace('#^https?://#', '', $node->getProperty('redirectUrl')); - if($this->endsWith($redirectUrl, '/') === TRUE){ - $redirectUrl = substr($redirectUrl, 0, -1); - } - if($this->startsWith($relativeUrl, '/') === TRUE){ - $relativeUrl = substr($relativeUrl, 1); - } - - if (in_array($redirectUrl, - array($relativeUrl, $relativeUrlWithQueryString, $absoluteUrl, $absoluteUrlWithQueryString), true)) { - + $redirectUrl = trim(preg_replace('#^https?://#', '', $node->getProperty('redirectUrl')), '/'); + if (in_array($redirectUrl, array($relativeUrl, $relativeUrlWithQueryString, $absoluteUrl, $absoluteUrlWithQueryString), true)) { $matchingNode = $node; break; } } + if (!isset($matchingNode)) { return false; } $this->setName('node'); $this->value = $matchingNode->getPath(); + return true; }