From fc04534e6c3213080b41021ab776f3de27cd1ad1 Mon Sep 17 00:00:00 2001 From: Jack Wilkinson Date: Wed, 29 Jun 2022 11:40:50 +0100 Subject: [PATCH 1/3] Added fix to ensure correct normalization return and aliased normalizeIdentifier() --- modules/system/classes/PluginManager.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/modules/system/classes/PluginManager.php b/modules/system/classes/PluginManager.php index 3581bae167..3c0695390e 100644 --- a/modules/system/classes/PluginManager.php +++ b/modules/system/classes/PluginManager.php @@ -571,11 +571,12 @@ public function getNamespace(PluginBase|string $plugin): string * Normalizes the provided plugin identifier (author.plugin) and resolves * it case-insensitively to the normalized identifier (Author.Plugin) * Returns the provided identifier if a match isn't found + * + * This is an alias for `getNormalizedIdentifier()` */ public function normalizeIdentifier(string $code): string { - $code = strtolower($code); - return $this->normalizedMap[$code] ?? $code; + return $this->getNormalizedIdentifier($code); } /** @@ -584,7 +585,8 @@ public function normalizeIdentifier(string $code): string */ public function getNormalizedIdentifier(PluginBase|string $plugin, bool $lower = false): string { - $identifier = $this->normalizeIdentifier($this->getIdentifier($plugin)); + $code = $this->getIdentifier($plugin); + $identifier = $this->normalizedMap[strtolower($code)] ?? $code; return $lower ? strtolower($identifier) : $identifier; } From b2c223f46d4288d02ff08810b04b326971ef1389 Mon Sep 17 00:00:00 2001 From: Jack Wilkinson Date: Wed, 29 Jun 2022 11:41:43 +0100 Subject: [PATCH 2/3] Added plugin normalization test --- .../tests/classes/PluginManagerTest.php | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/modules/system/tests/classes/PluginManagerTest.php b/modules/system/tests/classes/PluginManagerTest.php index 426cfb14ea..7c08858516 100644 --- a/modules/system/tests/classes/PluginManagerTest.php +++ b/modules/system/tests/classes/PluginManagerTest.php @@ -6,6 +6,7 @@ use System\Classes\PluginManager; use System\Classes\UpdateManager; use System\Classes\VersionManager; +use System\Classes\PluginBase; use ReflectionClass; use Winter\Storm\Database\Model as ActiveRecord; @@ -543,4 +544,49 @@ public function testFlagDisabling() $flags = $this->manager->getPluginFlags($plugin); $this->assertEmpty($flags); } + + public function testPluginNormalization() + { + // test lower to upper + $this->assertEquals('Database.Tester', $this->manager->normalizeIdentifier('database.tester')); + $this->assertEquals('Database.Tester', $this->manager->getNormalizedIdentifier('database.tester')); + + // test exact match + $this->assertEquals('DependencyTest.Found', $this->manager->normalizeIdentifier('DependencyTest.Found')); + $this->assertEquals('DependencyTest.Found', $this->manager->getNormalizedIdentifier('DependencyTest.Found')); + + // test mixed case + $this->assertEquals('DependencyTest.Found', $this->manager->normalizeIdentifier('Dependencytest.Found')); + $this->assertEquals('DependencyTest.Found', $this->manager->getNormalizedIdentifier('Dependencytest.Found')); + + // test typeo + $this->assertEquals('dpendencytest.Found', $this->manager->normalizeIdentifier('dpendencytest.Found')); + $this->assertEquals('dpendencytest.Found', $this->manager->getNormalizedIdentifier('dpendencytest.Found')); + $this->assertEquals('Winter.NoUpdate', $this->manager->normalizeIdentifier('Winter.NoUpdate')); + $this->assertEquals('Winter.NoUpdate', $this->manager->getNormalizedIdentifier('Winter.NoUpdate')); + + // test multiple mixed case installed plugin + $this->assertEquals('Winter.NoUpdates', $this->manager->normalizeIdentifier('Winter.NoUpdates')); + $this->assertEquals('Winter.NoUpdates', $this->manager->normalizeIdentifier('winter.noUpdates')); + $this->assertEquals('Winter.NoUpdates', $this->manager->normalizeIdentifier('winter.noupdates')); + $this->assertEquals('Winter.NoUpdates', $this->manager->getNormalizedIdentifier('Winter.NoUpdates')); + $this->assertEquals('Winter.NoUpdates', $this->manager->getNormalizedIdentifier('winter.noUpdates')); + $this->assertEquals('Winter.NoUpdates', $this->manager->getNormalizedIdentifier('winter.noupdates')); + + // test multiple mixed case not installed plugin + $this->assertEquals('Winter.MissingPlugin', $this->manager->normalizeIdentifier('Winter.MissingPlugin')); + $this->assertEquals('Winter.Missingplugin', $this->manager->normalizeIdentifier('Winter.Missingplugin')); + $this->assertEquals('Winter.missingplugin', $this->manager->normalizeIdentifier('Winter.missingplugin')); + $this->assertEquals('winter.missingplugin', $this->manager->normalizeIdentifier('winter.missingplugin')); + $this->assertEquals('Winter.MissingPlugin', $this->manager->getNormalizedIdentifier('Winter.MissingPlugin')); + $this->assertEquals('Winter.Missingplugin', $this->manager->getNormalizedIdentifier('Winter.Missingplugin')); + $this->assertEquals('Winter.missingplugin', $this->manager->getNormalizedIdentifier('Winter.missingplugin')); + $this->assertEquals('winter.missingplugin', $this->manager->getNormalizedIdentifier('winter.missingplugin')); + + // test passing plugin object + $plugin = $this->manager->findByIdentifier('Winter.NoUpdates'); + $this->assertInstanceOf(PluginBase::class, $plugin); + + $this->assertEquals('Winter.NoUpdates', $this->manager->getNormalizedIdentifier($plugin)); + } } From a97d1d90200e395065d11463888d7c49bc6bfbc8 Mon Sep 17 00:00:00 2001 From: Ben Thomson Date: Wed, 29 Jun 2022 19:54:36 +0800 Subject: [PATCH 3/3] Update modules/system/classes/PluginManager.php --- modules/system/classes/PluginManager.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/modules/system/classes/PluginManager.php b/modules/system/classes/PluginManager.php index 3c0695390e..e265b25e03 100644 --- a/modules/system/classes/PluginManager.php +++ b/modules/system/classes/PluginManager.php @@ -571,8 +571,6 @@ public function getNamespace(PluginBase|string $plugin): string * Normalizes the provided plugin identifier (author.plugin) and resolves * it case-insensitively to the normalized identifier (Author.Plugin) * Returns the provided identifier if a match isn't found - * - * This is an alias for `getNormalizedIdentifier()` */ public function normalizeIdentifier(string $code): string {