Skip to content

Conversation

Copy link

Copilot AI commented Dec 22, 2025

When users pass plugin/theme names with invalid characters to scaffold plugin-tests or scaffold theme-tests, the generated bootstrap.php contains corrupted file paths like '/my-plugin/.php', causing PHP fatal errors on test execution.

Changes

  • Strict Validation: Added regex validation in scaffold_plugin_theme_tests() to only allow alphanumeric characters (a-z, A-Z, 0-9) and dashes (-)
  • Error handling: Shows clear error message instead of silently creating corrupted files
  • Test coverage: Added Behat scenarios for both plugin-tests and theme-tests commands to verify rejection of invalid characters

Example

// Before: wp scaffold plugin-tests my-plugin/
// Generated: require dirname( dirname( __FILE__ ) ) . '/my-plugin/.php';  ❌

// After: wp scaffold plugin-tests my-plugin/
// Error: Invalid plugin slug specified. The slug can only contain alphanumeric characters and dashes.

The validation rejects:

  • Slashes: my-plugin/ or my-plugin\
  • Underscores: my_plugin
  • Special characters: my@plugin, my.plugin
  • Spaces: my plugin
  • Parent directory references: ../plugin

The fix follows the existing pattern for invalid slug validation (. and ..) and implements the hard-error approach rather than silently transforming input.

Original prompt

This section details on the original issue you should resolve

<issue_title>Adding slashes at the end of plugin name on 'plugin-tests' subcomand generates corrupted bootstrap.php</issue_title>
<issue_description>Adding one or more slashes at the end of plugin name like for example:

%> wp-cli scaffold plugin-tests my-plugin/

runs right, but causes the creation of a corrupted bootstrap.php file that produces a PHP Fatal error on require() that file when launching tests.
(The usual message is like following: "PHP Fatal error: require(): Failed opening required '/path/to/my-plugin/.php' (include_path='.') in /path/to/my-plugin/tests/bootstrap.php on line 26.")

I'd like to send a PR in order to fix this for example by right trimming slashes to $slug before to send to mustache template.
</issue_description>

Comments on the Issue (you are @copilot in this section)

@danielbachhuber > I'd like to send a PR in order to fix this for example by right trimming slashes to `$slug` before to send to mustache template.

What do you think about hard-erroring instead? I'm not sure it makes sense to magically transform user input in this case; probably better to inform the user they've provided invalid input (as we've done in #26)</comment_new>
<comment_new>@danielbachhuber

So I'd like to send a PR very soon.

Sounds good! I'll defer to your judgement on what changes make sense.</comment_new>


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix corrupted bootstrap.php generation with trailing slashes Reject plugin/theme slugs ending with slashes in scaffold tests commands Dec 22, 2025
Copilot AI requested a review from swissspidy December 22, 2025 16:34
Copilot AI and others added 2 commits December 23, 2025 08:36
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copilot AI changed the title Reject plugin/theme slugs ending with slashes in scaffold tests commands Add strict slug validation for plugin-tests and theme-tests commands Dec 23, 2025
Copilot AI requested a review from swissspidy December 23, 2025 08:39
@codecov
Copy link

codecov bot commented Dec 23, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@swissspidy swissspidy marked this pull request as ready for review December 23, 2025 17:21
@swissspidy swissspidy requested a review from a team as a code owner December 23, 2025 17:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Adding slashes at the end of plugin name on 'plugin-tests' subcomand generates corrupted bootstrap.php

2 participants