From 0dd2ab1a8a3921bb9eb3dac718a739fb44b0652e Mon Sep 17 00:00:00 2001 From: Nilambar Sharma Date: Fri, 13 Sep 2024 14:27:26 +0545 Subject: [PATCH 1/2] Improve check for Requires Plugins header --- .../Checker/Checks/Plugin_Repo/Plugin_Header_Fields_Check.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/Checker/Checks/Plugin_Repo/Plugin_Header_Fields_Check.php b/includes/Checker/Checks/Plugin_Repo/Plugin_Header_Fields_Check.php index 1f8cec4b0..af1496c0d 100644 --- a/includes/Checker/Checks/Plugin_Repo/Plugin_Header_Fields_Check.php +++ b/includes/Checker/Checks/Plugin_Repo/Plugin_Header_Fields_Check.php @@ -211,7 +211,7 @@ public function run( Check_Result $result ) { } if ( ! empty( $plugin_header['RequiresPlugins'] ) ) { - if ( ! preg_match( '/^[a-z0-9-]+(?:,[a-z0-9-]+)*$/', $plugin_header['RequiresPlugins'] ) ) { + if ( ! preg_match( '/^[a-z0-9-]+(?:,\s*[a-z0-9-]+)*$/', $plugin_header['RequiresPlugins'] ) ) { $this->add_result_warning_for_file( $result, sprintf( From a5b65ed2873d7777bdb06e22276feea3e416a84a Mon Sep 17 00:00:00 2001 From: Nilambar Sharma Date: Fri, 13 Sep 2024 14:47:15 +0545 Subject: [PATCH 2/2] Add test for required plugins header --- .../load.php | 1 + .../Plugin_Header_Fields_Check_Tests.php | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/tests/phpunit/testdata/plugins/test-plugin-unfiltered-uploads-with-errors/load.php b/tests/phpunit/testdata/plugins/test-plugin-unfiltered-uploads-with-errors/load.php index f08bd8811..8e0d259cf 100644 --- a/tests/phpunit/testdata/plugins/test-plugin-unfiltered-uploads-with-errors/load.php +++ b/tests/phpunit/testdata/plugins/test-plugin-unfiltered-uploads-with-errors/load.php @@ -11,6 +11,7 @@ * License: GPLv2 or later * License URI: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html * Text Domain: test-plugin-unfiltered-uploads-errors + * Requires Plugins: woocommerce, contact-form-7 * * @package test-plugin-unfiltered-uploads-errors */ diff --git a/tests/phpunit/tests/Checker/Checks/Plugin_Header_Fields_Check_Tests.php b/tests/phpunit/tests/Checker/Checks/Plugin_Header_Fields_Check_Tests.php index ceb65ffdf..d56ad15f8 100644 --- a/tests/phpunit/tests/Checker/Checks/Plugin_Header_Fields_Check_Tests.php +++ b/tests/phpunit/tests/Checker/Checks/Plugin_Header_Fields_Check_Tests.php @@ -34,4 +34,23 @@ public function test_run_with_errors() { $this->assertCount( 1, wp_list_filter( $warnings['load.php'][0][0], array( 'code' => 'plugin_header_invalid_requires_plugins' ) ) ); } } + + public function test_run_with_valid_requires_plugins_header() { + /* + * Test plugin has following valid header. + * Requires Plugins: woocommerce, contact-form-7 + */ + + $check = new Plugin_Header_Fields_Check(); + $check_context = new Check_Context( UNIT_TESTS_PLUGIN_DIR . 'test-plugin-unfiltered-uploads-with-errors/load.php' ); + $check_result = new Check_Result( $check_context ); + + $check->run( $check_result ); + + $warnings = $check_result->get_warnings(); + + if ( is_wp_version_compatible( '6.5' ) ) { + $this->assertCount( 0, wp_list_filter( $warnings['load.php'][0][0], array( 'code' => 'plugin_header_invalid_requires_plugins' ) ) ); + } + } }