EspoCRM – Open Source CRM Application
PHP calendarcontactscrmcrm-platformcrm-systemcustomer-portalcustomer-supportcustomizabledocumentsemail-marketingkanbanleadsopen-sourcephpplatformsales-automationsingle-page-applicationsupport
Added reserved custom paths
Taras Machyshynf3c8c44582a5
diff --git a/application/Espo/Core/Utils/File/Manager.php b/application/Espo/Core/Utils/File/Manager.phpindex f2a6614157..0a222db44e 100644--- a/application/Espo/Core/Utils/File/Manager.php+++ b/application/Espo/Core/Utils/File/Manager.php@@ -51,6 +51,12 @@ class Managerprotected const GET_SAFE_CONTENTS_RETRY_NUMBER = 10;protected const GET_SAFE_CONTENTS_RETRY_INTERVAL = 0.1;+ private const RESERVED_CUSTOM_PATH_LIST = [+ 'custom/Espo/Custom',+ 'custom/Espo/Modules',+ 'client/custom/modules',+ ];+/*** @param ?array{* dir: string|int|null,@@ -701,6 +707,10 @@ class Manager$result = true;foreach ($dirPaths as $dirPath) {+ if ($this->isReservedCustomPath($dirPath)) {+ continue;+ }+if (is_dir($dirPath) && is_writable($dirPath)) {$result &= rmdir($dirPath);}@@ -1160,4 +1170,19 @@ class Manageropcache_invalidate($filepath, $force);} catch (Throwable) {}}++ private function isReservedCustomPath(string $path): bool+ {+ $normalizedPath = trim($path, '/');++ foreach (self::RESERVED_CUSTOM_PATH_LIST as $ignoredPath) {+ $normalizedIgnoredPath = trim($ignoredPath, '/');++ if ($normalizedPath === $normalizedIgnoredPath) {+ return true;+ }+ }++ return false;+ }}diff --git a/tests/unit/Espo/Core/Utils/File/ManagerTest.php b/tests/unit/Espo/Core/Utils/File/ManagerTest.phpindex d3c9f7756a..f0ed7b0df5 100644--- a/tests/unit/Espo/Core/Utils/File/ManagerTest.php+++ b/tests/unit/Espo/Core/Utils/File/ManagerTest.php@@ -532,4 +532,27 @@ class ManagerTest extends TestCase$this->fileManager->getRelativePath($path, $basePath, $dirSeparator));}++ public static function reservedCustomPathData(): array+ {+ return [+ ['custom/Espo/Custom', true],+ ['custom/Espo/Modules', true],+ ['client/custom/modules', true],+ ['client/custom/modules/', true],+ ['custom/Espo/Custom/Resources', false],+ ['custom/Espo/Modules/Test', false],+ ['client/custom/modules/test', false],+ ['application/Espo/Core', false],+ ];+ }++ #[DataProvider('reservedCustomPathData')]+ public function testIsReservedCustomPath(string $path, bool $expectedResult): void+ {+ $this->assertEquals(+ $expectedResult,+ $this->reflection->invokeMethod('isReservedCustomPath', [$path])+ );+ }}