From 0aa9f32fb139a2e69e6e8eab40e4391a825ad598 Mon Sep 17 00:00:00 2001 From: "Dion Hulse (dd32)" Date: Thu, 9 Jul 2020 10:42:08 +1000 Subject: [PATCH 1/2] Autoloader: Avoid a PHP warning when an empty string is passed to `is_directory_plugin()`. Example Warning: `strpos(): Offset not contained in string`. --- 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..e0b70bf3f3d53 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_slash() { + $this->assertFalse( $this->plugins_handler->is_directory_plugin( '' ) ); + } + /** * Tests is_directory_plugin() with a single-file plugin that begins with '/'. * From 4860b7ef7a4b08d2bfbec188976747a1379a6ad7 Mon Sep 17 00:00:00 2001 From: Brandon Kraft Date: Wed, 8 Jul 2020 20:38:40 -0500 Subject: [PATCH 2/2] Update packages/autoloader/tests/php/test_plugins_handler.php --- packages/autoloader/tests/php/test_plugins_handler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/autoloader/tests/php/test_plugins_handler.php b/packages/autoloader/tests/php/test_plugins_handler.php index e0b70bf3f3d53..d174a98d0e14f 100644 --- a/packages/autoloader/tests/php/test_plugins_handler.php +++ b/packages/autoloader/tests/php/test_plugins_handler.php @@ -78,7 +78,7 @@ public function test_is_directory_plugin_single_file() { * * @covers Plugins_Handler::is_directory_plugin */ - public function test_is_directory_plugin_single_file_with_slash() { + public function test_is_directory_plugin_single_file_with_empty_string() { $this->assertFalse( $this->plugins_handler->is_directory_plugin( '' ) ); }