From 2927b61c7fb7b2373e336ff11461a715938d4807 Mon Sep 17 00:00:00 2001 From: Dion Hulse Date: Thu, 9 Jul 2020 23:17:03 +1000 Subject: [PATCH] Autoloader: Avoid a PHP warning when an empty string is passed to `is_directory_plugin()`. (#16442) Co-authored-by: Brandon Kraft --- packages/autoloader/src/class-plugins-handler.php | 2 +- packages/autoloader/tests/php/test_plugins_handler.php | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/autoloader/src/class-plugins-handler.php b/packages/autoloader/src/class-plugins-handler.php index 76f66e6f839f3..9d981f1274c90 100644 --- a/packages/autoloader/src/class-plugins-handler.php +++ b/packages/autoloader/src/class-plugins-handler.php @@ -68,7 +68,7 @@ private function create_plugin_path( $plugin_slug ) { * @return bool */ public function is_directory_plugin( $plugin ) { - return false !== strpos( $plugin, '/', 1 ); + return strlen( $plugin ) > 1 && false !== strpos( $plugin, '/', 1 ); } /** diff --git a/packages/autoloader/tests/php/test_plugins_handler.php b/packages/autoloader/tests/php/test_plugins_handler.php index 133aa722a4cd7..d174a98d0e14f 100644 --- a/packages/autoloader/tests/php/test_plugins_handler.php +++ b/packages/autoloader/tests/php/test_plugins_handler.php @@ -73,6 +73,15 @@ public function test_is_directory_plugin_single_file() { $this->assertFalse( $this->plugins_handler->is_directory_plugin( 'test.php' ) ); } + /** + * Tests is_directory_plugin() with an empty string. + * + * @covers Plugins_Handler::is_directory_plugin + */ + public function test_is_directory_plugin_single_file_with_empty_string() { + $this->assertFalse( $this->plugins_handler->is_directory_plugin( '' ) ); + } + /** * Tests is_directory_plugin() with a single-file plugin that begins with '/'. *