Skip to content

Commit db611c8

Browse files
authoredMay 7, 2024
Fix memory leak: infinite loop because a path info is returned even if not valid
1 parent 860af9e commit db611c8

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed
 

‎Plugin/App/Request/StorePathInfoValidator.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use Magento\Store\Model\Store;
1616
use Opengento\StorePathUrl\Model\Config;
1717

18-
use function explode;
1918
use function parse_url;
2019
use function strtok;
2120

@@ -31,21 +30,22 @@ public function __construct(
3130
public function beforeGetValidStoreCode(Subject $subject, Http $request, string $pathInfo = ''): array
3231
{
3332
if ($this->config->isEnabled()) {
34-
$uri = explode('?', $request->getUriString())[0] . '/';
35-
if ($pathInfo === '') {
36-
$pathInfo = parse_url($uri, PHP_URL_PATH);
37-
if ($pathInfo === false) {
38-
return [$request, $pathInfo];
33+
$uri = strtok($request->getUriString(), '?') . '/';
34+
if ($uri !== false) {
35+
if ($pathInfo === '') {
36+
$pathInfo = parse_url($uri, PHP_URL_PATH);
37+
if ($pathInfo !== false) {
38+
$pathInfo = strtok($pathInfo, '/');
39+
}
3940
}
40-
$pathInfo = strtok($pathInfo, '/');
41+
$pathInfo = $pathInfo === false ? $this->resolveByWebUrl($uri) : $this->resolveByLinkUrl($uri);
4142
}
42-
$pathInfo = $pathInfo === false ? $this->resolveByWebUrl($uri) : $this->resolveByLinkUrl($uri, $pathInfo);
4343
}
4444

4545
return [$request, $pathInfo];
4646
}
4747

48-
private function resolveByLinkUrl(string $uri, string $pathInfo): string
48+
private function resolveByLinkUrl(string $uri): string
4949
{
5050
/** @var Store $store */
5151
foreach ($this->storeRepository->getList() as $store) {
@@ -54,7 +54,7 @@ private function resolveByLinkUrl(string $uri, string $pathInfo): string
5454
}
5555
}
5656

57-
return $pathInfo;
57+
return '';
5858
}
5959

6060
private function resolveByWebUrl(string $uri): string

0 commit comments

Comments
 (0)
Please sign in to comment.