From 604f0d060dda57010230cfeca243e0afd868d7af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20K=C3=BCndig?= Date: Tue, 2 Jul 2019 16:12:29 +0200 Subject: [PATCH] Make plugin dependency checks case-insensitive (#4337) Normalize the plugin identifier before lookup in the `hasPlugin` call, which should allow plugin dependencies to resolve if mis-cased in the Plugin `$require` property. Credit to @tobias-kuendig. --- modules/system/classes/PluginManager.php | 8 +++----- tests/unit/system/classes/PluginManagerTest.php | 4 ++-- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/modules/system/classes/PluginManager.php b/modules/system/classes/PluginManager.php index 35300f6bf..a92ea6490 100644 --- a/modules/system/classes/PluginManager.php +++ b/modules/system/classes/PluginManager.php @@ -363,7 +363,9 @@ class PluginManager { $classId = $this->getIdentifier($namespace); - return isset($this->plugins[$classId]); + $normalized = $this->normalizeIdentifier($classId); + + return isset($this->plugins[$normalized]); } /** @@ -707,13 +709,11 @@ class PluginManager $loopCount = 0; while (count($checklist)) { - if (++$loopCount > 999) { throw new ApplicationException('Too much recursion'); } foreach ($checklist as $code => $plugin) { - /* * Get dependencies and remove any aliens */ @@ -745,9 +745,7 @@ class PluginManager array_push($result, $code); unset($checklist[$code]); } - } - return $result; } diff --git a/tests/unit/system/classes/PluginManagerTest.php b/tests/unit/system/classes/PluginManagerTest.php index 445d709ea..9130b926c 100644 --- a/tests/unit/system/classes/PluginManagerTest.php +++ b/tests/unit/system/classes/PluginManagerTest.php @@ -117,10 +117,10 @@ class PluginManagerTest extends TestCase * Test case for https://github.com/octobercms/october/pull/4337 */ $result = $this->manager->hasPlugin('dependencyTest\Wrongcase'); - $this->assertFalse($result); + $this->assertTrue($result); $result = $this->manager->hasPlugin('dependencyTest.Wrongcase'); - $this->assertFalse($result); + $this->assertTrue($result); } public function testGetPluginNamespaces()