Skip to content

Commit a913cf4

Browse files
swissspidyCopilot
andauthored
Reject invalid Requires at least header values (#392)
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent 5bffaf9 commit a913cf4

2 files changed

Lines changed: 30 additions & 3 deletions

File tree

‎features/scaffold-plugin-tests.feature‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,31 @@ Feature: Scaffold plugin unit tests
143143
SKIP_DB_CREATE=true
144144
"""
145145

146+
Scenario: Scaffold plugin tests ignore invalid version in readme.txt
147+
Given a WP install
148+
And I run `wp scaffold plugin hello-world --skip-tests`
149+
150+
When I run `wp plugin path hello-world --dir`
151+
Then save STDOUT as {PLUGIN_DIR}
152+
153+
Given a {PLUGIN_DIR}/readme.txt file:
154+
"""
155+
=== Hello World ===
156+
Requires at least: 6.4; echo exploit #
157+
Tested up to: 6.4
158+
"""
159+
160+
When I run `wp scaffold plugin-tests hello-world --ci=circle`
161+
Then STDOUT should not be empty
162+
And the {PLUGIN_DIR}/.circleci/config.yml file should not contain:
163+
"""
164+
6.4; echo exploit #
165+
"""
166+
And the {PLUGIN_DIR}/.circleci/config.yml file should contain:
167+
"""
168+
bash bin/install-wp-tests.sh wordpress_test root '' 127.0.0.1 latest $SKIP_DB_CREATE
169+
"""
170+
146171
Scenario: Scaffold plugin tests with Gitlab as the provider
147172
Given a WP install
148173
And I run `wp scaffold plugin hello-world --skip-tests`

‎src/Scaffold_Command.php‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -893,9 +893,11 @@ private function scaffold_plugin_theme_tests( $args, $assoc_args, $type ) {
893893
if ( file_exists( "{$target_dir}/readme.txt" ) ) {
894894
$readme_content = (string) file_get_contents( "{$target_dir}/readme.txt" );
895895

896-
preg_match( '/Requires at least\:(.*)\n/m', $readme_content, $matches );
897-
if ( isset( $matches[1] ) && $matches[1] ) {
898-
$wp_versions_to_test[] = trim( $matches[1] );
896+
if ( preg_match( '/Requires at least\:(.*)(?:\r?\n|$)/i', $readme_content, $matches ) ) {
897+
$version = trim( $matches[1] );
898+
if ( preg_match( '/^[0-9]+(?:\.[0-9]+)*(?:-[a-zA-Z0-9.]+)?$/', $version ) ) {
899+
$wp_versions_to_test[] = $version;
900+
}
899901
}
900902
}
901903
$wp_versions_to_test[] = 'latest';

0 commit comments

Comments
 (0)