diff --git a/includes/Checker/Checks/Plugin_Repo/Plugin_Readme_Check.php b/includes/Checker/Checks/Plugin_Repo/Plugin_Readme_Check.php index f51dbed9f..eea1b489a 100644 --- a/includes/Checker/Checks/Plugin_Repo/Plugin_Readme_Check.php +++ b/includes/Checker/Checks/Plugin_Repo/Plugin_Readme_Check.php @@ -754,9 +754,8 @@ private function check_for_contributors( Check_Result $result, string $readme_fi return; } - $usernames = explode( ',', $matches[1] ); - - $usernames = array_unique( array_map( 'trim', $usernames ) ); + $usernames = explode( ',', trim( $matches[1], ' ,' ) ); + $usernames = array_filter( array_unique( array_map( 'trim', $usernames ) ) ); $valid = true; diff --git a/tests/phpunit/testdata/plugins/test-plugin-readme-contributors-formatting/load.php b/tests/phpunit/testdata/plugins/test-plugin-readme-contributors-formatting/load.php new file mode 100644 index 000000000..f85762b73 --- /dev/null +++ b/tests/phpunit/testdata/plugins/test-plugin-readme-contributors-formatting/load.php @@ -0,0 +1,17 @@ +assertCount( 0, wp_list_filter( $warnings['readme.txt'][0][0], array( 'code' => 'readme_invalid_contributors' ) ) ); } + public function test_run_without_errors_readme_contributors_formatting() { + $readme_check = new Plugin_Readme_Check(); + $check_context = new Check_Context( UNIT_TESTS_PLUGIN_DIR . 'test-plugin-readme-contributors-formatting/load.php' ); + $check_result = new Check_Result( $check_context ); + + $readme_check->run( $check_result ); + + $warnings = $check_result->get_warnings(); + + // Should not contain contributors warning even with leading/trailing spaces and commas. + $this->assertCount( 0, wp_list_filter( $warnings['readme.txt'][0][0], array( 'code' => 'readme_invalid_contributors' ) ) ); + } + public function test_run_with_mismatched_requires_headers() { $check = new Plugin_Readme_Check(); $check_context = new Check_Context( UNIT_TESTS_PLUGIN_DIR . 'test-trademarks-plugin-readme-errors/load.php' );