From 6585d499f5aca7f03e87710aeb8a277cb7dc7e5e Mon Sep 17 00:00:00 2001 From: Florian Thoma Date: Mon, 13 Feb 2023 16:18:44 +1100 Subject: [PATCH] FIX Convert slashes in paths when getting list of classes for file/folder This is to support the mechanism working on all operating systems where Windows may produce a mix of forward and backward slashes in some paths. For working with the files it may not be a problem, but for exact string comparison the path delimiters need to be unified. --- src/Core/ClassInfo.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Core/ClassInfo.php b/src/Core/ClassInfo.php index 38542c1d3..6ac4c58d4 100644 --- a/src/Core/ClassInfo.php +++ b/src/Core/ClassInfo.php @@ -301,14 +301,14 @@ class ClassInfo */ public static function classes_for_file($filePath) { - $absFilePath = Director::getAbsFile($filePath); + $absFilePath = Convert::slashes(Director::getAbsFile($filePath)); $classManifest = ClassLoader::inst()->getManifest(); $classes = $classManifest->getClasses(); $classNames = $classManifest->getClassNames(); $matchedClasses = []; foreach ($classes as $lowerClass => $compareFilePath) { - if (strcasecmp($absFilePath ?? '', $compareFilePath ?? '') === 0) { + if (strcasecmp($absFilePath, Convert::slashes($compareFilePath ?? '')) === 0) { $matchedClasses[$lowerClass] = $classNames[$lowerClass]; } } @@ -324,14 +324,14 @@ class ClassInfo */ public static function classes_for_folder($folderPath) { - $absFolderPath = Director::getAbsFile($folderPath); + $absFolderPath = Convert::slashes(Director::getAbsFile($folderPath)); $classManifest = ClassLoader::inst()->getManifest(); $classes = $classManifest->getClasses(); $classNames = $classManifest->getClassNames(); $matchedClasses = []; foreach ($classes as $lowerClass => $compareFilePath) { - if (stripos($compareFilePath ?? '', $absFolderPath ?? '') === 0) { + if (stripos(Convert::slashes($compareFilePath ?? ''), $absFolderPath) === 0) { $matchedClasses[$lowerClass] = $classNames[$lowerClass]; } }