From d9a52efef8f0079e313c1b701651180c57349984 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Thu, 18 Apr 2024 17:42:46 +0200 Subject: [PATCH 1/3] Less memory hungry FnMatchPathNormalizer: reduce ~35-45% less consumption --- .../FileSystem/FnMatchPathNormalizer.php | 28 ++++--------------- 1 file changed, 5 insertions(+), 23 deletions(-) diff --git a/src/Skipper/FileSystem/FnMatchPathNormalizer.php b/src/Skipper/FileSystem/FnMatchPathNormalizer.php index 7d30de3658..50f85b29fb 100644 --- a/src/Skipper/FileSystem/FnMatchPathNormalizer.php +++ b/src/Skipper/FileSystem/FnMatchPathNormalizer.php @@ -11,34 +11,16 @@ */ final class FnMatchPathNormalizer { - /** - * @var string - * @see https://regex101.com/r/ZB2dFV/2 - */ - private const ONLY_ENDS_WITH_ASTERISK_REGEX = '#^[^*](.*?)\*$#'; - - /** - * @var string - * @see https://regex101.com/r/aVUDjM/2 - */ - private const ONLY_STARTS_WITH_ASTERISK_REGEX = '#^\*(.*?)[^*]$#'; - public function normalizeForFnmatch(string $path): string { - // ends with * - if (Strings::match($path, self::ONLY_ENDS_WITH_ASTERISK_REGEX)) { - return '*' . $path; - } - - // starts with * - if (Strings::match($path, self::ONLY_STARTS_WITH_ASTERISK_REGEX)) { - return $path . '*'; + if (str_ends_with($path, '*') || str_starts_with($path, '*')) { + return '*' . trim($path, '*') . '*'; } if (\str_contains($path, '..')) { - /** @var string|false $path */ - $path = realpath($path); - if ($path === false) { + /** @var string|false $realPath */ + $realPath = realpath($path); + if ($realPath === false) { return ''; } } From fc4c167c6b6cb8c9f18a2e6828b25f80aeb876d0 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Thu, 18 Apr 2024 18:01:51 +0200 Subject: [PATCH 2/3] fix typo --- src/Skipper/FileSystem/FnMatchPathNormalizer.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Skipper/FileSystem/FnMatchPathNormalizer.php b/src/Skipper/FileSystem/FnMatchPathNormalizer.php index 50f85b29fb..9f0677e9f1 100644 --- a/src/Skipper/FileSystem/FnMatchPathNormalizer.php +++ b/src/Skipper/FileSystem/FnMatchPathNormalizer.php @@ -23,6 +23,7 @@ public function normalizeForFnmatch(string $path): string if ($realPath === false) { return ''; } + return $realPath; } return $path; From e62440de32c9a6e87a507bbd0c84f59b7a51d11f Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Thu, 18 Apr 2024 18:05:34 +0200 Subject: [PATCH 3/3] cs --- src/Skipper/FileSystem/FnMatchPathNormalizer.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Skipper/FileSystem/FnMatchPathNormalizer.php b/src/Skipper/FileSystem/FnMatchPathNormalizer.php index 9f0677e9f1..3a3de85771 100644 --- a/src/Skipper/FileSystem/FnMatchPathNormalizer.php +++ b/src/Skipper/FileSystem/FnMatchPathNormalizer.php @@ -23,6 +23,7 @@ public function normalizeForFnmatch(string $path): string if ($realPath === false) { return ''; } + return $realPath; }