From 7f910682cd51567d6ae5606a2edcd756f4cc79b0 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 3 Feb 2025 21:35:57 +0700 Subject: [PATCH] [Performance] Use exactly equal or append / file path check on RealpathMatcher (#6716) --- src/Skipper/RealpathMatcher.php | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/Skipper/RealpathMatcher.php b/src/Skipper/RealpathMatcher.php index f912000c48..6a947fd26b 100644 --- a/src/Skipper/RealpathMatcher.php +++ b/src/Skipper/RealpathMatcher.php @@ -23,16 +23,13 @@ public function match(string $matchingPath, string $filePath): bool $normalizedMatchingPath = PathNormalizer::normalize($realPathMatchingPath); $normalizedFilePath = PathNormalizer::normalize($realpathFilePath); - // skip define direct path - if (is_file($normalizedMatchingPath)) { - return $normalizedMatchingPath === $normalizedFilePath; + // skip define direct path exactly equal + if ($normalizedMatchingPath === $normalizedFilePath) { + return true; } // ensure add / suffix to ensure no same prefix directory - if (is_dir($normalizedMatchingPath)) { - $normalizedMatchingPath = rtrim($normalizedMatchingPath, '/') . '/'; - } - - return str_starts_with($normalizedFilePath, $normalizedMatchingPath); + $suffixedMatchingPath = rtrim($normalizedMatchingPath, '/') . '/'; + return str_starts_with($normalizedFilePath, $suffixedMatchingPath); } }