Skip to content

Commit

Permalink
Fix memory leak: infinite loop because a path info is returned even i…
Browse files Browse the repository at this point in the history
…f not valid
  • Loading branch information
thomas-kl1 authored May 7, 2024
1 parent 860af9e commit db611c8
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions Plugin/App/Request/StorePathInfoValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use Magento\Store\Model\Store;
use Opengento\StorePathUrl\Model\Config;

use function explode;
use function parse_url;
use function strtok;

Expand All @@ -31,21 +30,22 @@ public function __construct(
public function beforeGetValidStoreCode(Subject $subject, Http $request, string $pathInfo = ''): array
{
if ($this->config->isEnabled()) {
$uri = explode('?', $request->getUriString())[0] . '/';
if ($pathInfo === '') {
$pathInfo = parse_url($uri, PHP_URL_PATH);
if ($pathInfo === false) {
return [$request, $pathInfo];
$uri = strtok($request->getUriString(), '?') . '/';
if ($uri !== false) {
if ($pathInfo === '') {
$pathInfo = parse_url($uri, PHP_URL_PATH);
if ($pathInfo !== false) {
$pathInfo = strtok($pathInfo, '/');
}
}
$pathInfo = strtok($pathInfo, '/');
$pathInfo = $pathInfo === false ? $this->resolveByWebUrl($uri) : $this->resolveByLinkUrl($uri);
}
$pathInfo = $pathInfo === false ? $this->resolveByWebUrl($uri) : $this->resolveByLinkUrl($uri, $pathInfo);
}

return [$request, $pathInfo];
}

private function resolveByLinkUrl(string $uri, string $pathInfo): string
private function resolveByLinkUrl(string $uri): string
{
/** @var Store $store */
foreach ($this->storeRepository->getList() as $store) {
Expand All @@ -54,7 +54,7 @@ private function resolveByLinkUrl(string $uri, string $pathInfo): string
}
}

return $pathInfo;
return '';
}

private function resolveByWebUrl(string $uri): string
Expand Down

0 comments on commit db611c8

Please sign in to comment.