Skip to content

Commit 8be3c3c

Browse files
fix(PathMatcher.php): allow /var/ root (#69)
* fix(PathMatcher.php): allow /var/ root Changed mayPathBeIncluded to allow root '/var/' dirctory while still checking for '/var/' in other parts of the path. Fixes #68 * removed use function added by PhpStorm --------- Co-authored-by: Russell Reynolds <rreynolds@aha-creative.com>
1 parent b13b27d commit 8be3c3c

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

‎src/Internal/Util/PathMatcher.php‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,10 @@ public static function mayPathBeIncluded(string $normalizedPath): bool
290290
}
291291
}
292292

293-
if (str_contains($canon, '/var/') || str_starts_with($canon, 'var/')) {
293+
if (str_starts_with($canon, 'var/')
294+
|| (!str_starts_with($canon, '/var/') && str_contains($canon, '/var/'))
295+
|| (str_starts_with($canon, '/var/') && str_contains(substr($canon, 4), '/var/'))
296+
) {
294297
if (! self::hasIncludeMatchingPrefix('var/', $includes)) {
295298
return false;
296299
}

‎tests/Internal/Util/PathMatcherTest.php‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,18 @@
250250
}
251251
});
252252

253+
test('permits var when var is root directory using default config', function () {
254+
try {
255+
Config::set([
256+
'include' => ['src/**', 'app/**', 'tests/**',],
257+
]);
258+
259+
expect(PathMatcher::mayPathBeIncluded('/var/www/app/src/index.php'))->toBeTrue();
260+
} finally {
261+
Config::reset();
262+
}
263+
});
264+
253265
test('permits vendor, var, or storage paths when explicitly whitelisted in include config', function () {
254266
try {
255267
Config::set([

0 commit comments

Comments
 (0)