Skip to content

Commit

Permalink
[Performance] Use exactly equal or append / file path check on Realpa…
Browse files Browse the repository at this point in the history
…thMatcher (#6716)
  • Loading branch information
samsonasik authored Feb 3, 2025
1 parent 4f54239 commit 7f91068
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/Skipper/RealpathMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 7f91068

Please sign in to comment.