From 6585d499f5aca7f03e87710aeb8a277cb7dc7e5e Mon Sep 17 00:00:00 2001 From: Florian Thoma Date: Mon, 13 Feb 2023 16:18:44 +1100 Subject: [PATCH 1/2] 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]; } } From 403f924d22455d2ba8f927888f7ee6d88b55e034 Mon Sep 17 00:00:00 2001 From: Maxime Rainville Date: Thu, 2 Mar 2023 09:56:40 +1300 Subject: [PATCH 2/2] BUG Update RelatedDataService to properly escape ClassName in Polymorphic relations (#10713) --- src/ORM/RelatedData/StandardRelatedDataService.php | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/ORM/RelatedData/StandardRelatedDataService.php b/src/ORM/RelatedData/StandardRelatedDataService.php index 04501fc23..c6be4632d 100644 --- a/src/ORM/RelatedData/StandardRelatedDataService.php +++ b/src/ORM/RelatedData/StandardRelatedDataService.php @@ -394,14 +394,7 @@ class StandardRelatedDataService implements RelatedDataService */ private function prepareClassNameLiteral(string $value): string { - $c = chr(92); - $escaped = str_replace($c ?? '', "{$c}{$c}", $value ?? ''); - // postgres - if (stripos(get_class(DB::get_conn()), 'postgres') !== false) { - return "E'{$escaped}'"; - } - // mysql - return "'{$escaped}'"; + return DB::get_conn()->quoteString($value); } /**