From a270964cdabe9f452e788281ced0ec4ca840b26d Mon Sep 17 00:00:00 2001 From: Russell Reynolds Date: Wed, 16 Sep 2026 18:20:36 -0500 Subject: [PATCH 1/2] 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 --- src/Internal/Util/PathMatcher.php | 7 ++++++- tests/Internal/Util/PathMatcherTest.php | 12 ++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/Internal/Util/PathMatcher.php b/src/Internal/Util/PathMatcher.php index 7a0b2d1b..b0c0d147 100644 --- a/src/Internal/Util/PathMatcher.php +++ b/src/Internal/Util/PathMatcher.php @@ -6,6 +6,8 @@ use TypePHP\Internal\Io\CacheManager; +use function substr; + require_once __DIR__ . '/../Io/CacheManager.php'; /** @@ -290,7 +292,10 @@ public static function mayPathBeIncluded(string $normalizedPath): bool } } - if (str_contains($canon, '/var/') || str_starts_with($canon, 'var/')) { + if (str_starts_with($canon, 'var/') + || (!str_starts_with($canon, '/var/') && str_contains($canon, '/var/')) + || (str_starts_with($canon, '/var/') && str_contains(substr($canon, 4), '/var/')) + ) { if (! self::hasIncludeMatchingPrefix('var/', $includes)) { return false; } diff --git a/tests/Internal/Util/PathMatcherTest.php b/tests/Internal/Util/PathMatcherTest.php index ab49b93b..130c9bec 100644 --- a/tests/Internal/Util/PathMatcherTest.php +++ b/tests/Internal/Util/PathMatcherTest.php @@ -250,6 +250,18 @@ } }); + test('permits var when var is root directory using default config', function () { + try { + Config::set([ + 'include' => ['src/**', 'app/**', 'tests/**',], + ]); + + expect(PathMatcher::mayPathBeIncluded('/var/www/app/src/index.php'))->toBeTrue(); + } finally { + Config::reset(); + } + }); + test('permits vendor, var, or storage paths when explicitly whitelisted in include config', function () { try { Config::set([ From 4f85f7705c97628c58e4783dc49dc450127e083f Mon Sep 17 00:00:00 2001 From: Russell Reynolds Date: Wed, 16 Sep 2026 18:45:11 -0500 Subject: [PATCH 2/2] removed use function added by PhpStorm --- src/Internal/Util/PathMatcher.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Internal/Util/PathMatcher.php b/src/Internal/Util/PathMatcher.php index b0c0d147..b06f39ce 100644 --- a/src/Internal/Util/PathMatcher.php +++ b/src/Internal/Util/PathMatcher.php @@ -6,8 +6,6 @@ use TypePHP\Internal\Io\CacheManager; -use function substr; - require_once __DIR__ . '/../Io/CacheManager.php'; /**