Skip to content

Commit a270964

Browse files
committed
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
1 parent a9e313f commit a270964

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

‎src/Internal/Util/PathMatcher.php‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
use TypePHP\Internal\Io\CacheManager;
88

9+
use function substr;
10+
911
require_once __DIR__ . '/../Io/CacheManager.php';
1012

1113
/**
@@ -290,7 +292,10 @@ public static function mayPathBeIncluded(string $normalizedPath): bool
290292
}
291293
}
292294

293-
if (str_contains($canon, '/var/') || str_starts_with($canon, 'var/')) {
295+
if (str_starts_with($canon, 'var/')
296+
|| (!str_starts_with($canon, '/var/') && str_contains($canon, '/var/'))
297+
|| (str_starts_with($canon, '/var/') && str_contains(substr($canon, 4), '/var/'))
298+
) {
294299
if (! self::hasIncludeMatchingPrefix('var/', $includes)) {
295300
return false;
296301
}

‎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)