Skip to content

Commit 37403a4

Browse files
CopilotswissspidyCopilot
authored
Fix child-theme scaffold error when --path contains relative segments (#384)
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Pascal Birchler <pascalb@google.com>
1 parent 1f42cac commit 37403a4

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

features/scaffold.feature

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,16 @@ Feature: WordPress code scaffolding
116116
"""
117117
And the return code should be 1
118118

119+
@theme
120+
Scenario: Scaffold a child theme with a relative --path argument containing '..'
121+
Given a WP install in 'subdir'
122+
And I run `wp --path=.. theme path` from 'subdir/wp-content'
123+
And save STDOUT as {THEME_DIR}
124+
125+
When I run `wp scaffold child-theme zombieland --parent_theme=umbrella --path=..` from 'subdir/wp-content'
126+
Then the {THEME_DIR}/zombieland/style.css file should exist
127+
And the {THEME_DIR}/zombieland/functions.php file should exist
128+
119129
@theme
120130
Scenario: Scaffold a child theme with dots in the slug
121131
Given a WP install

src/Scaffold_Command.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -986,12 +986,14 @@ static function ( $item ) use ( $slug ) {
986986
private function check_target_directory( $type, $target_dir ) {
987987
$parent_dir = dirname( self::canonicalize_path( str_replace( '\\', '/', $target_dir ) ) );
988988

989-
if ( 'theme' === $type && str_replace( '\\', '/', WP_CONTENT_DIR . '/themes' ) !== $parent_dir ) {
990-
return sprintf( 'The target directory \'%1$s\' is not in \'%2$s\'.', $target_dir, WP_CONTENT_DIR . '/themes' );
989+
$themes_dir = self::canonicalize_path( str_replace( '\\', '/', WP_CONTENT_DIR . '/themes' ) );
990+
if ( 'theme' === $type && $themes_dir !== $parent_dir ) {
991+
return sprintf( 'The target directory \'%1$s\' is not in \'%2$s\'.', $target_dir, $themes_dir );
991992
}
992993

993-
if ( 'plugin' === $type && str_replace( '\\', '/', WP_PLUGIN_DIR ) !== $parent_dir ) {
994-
return sprintf( 'The target directory \'%1$s\' is not in \'%2$s\'.', $target_dir, WP_PLUGIN_DIR );
994+
$plugins_dir = self::canonicalize_path( str_replace( '\\', '/', WP_PLUGIN_DIR ) );
995+
if ( 'plugin' === $type && $plugins_dir !== $parent_dir ) {
996+
return sprintf( 'The target directory \'%1$s\' is not in \'%2$s\'.', $target_dir, $plugins_dir );
995997
}
996998

997999
// Success.

0 commit comments

Comments
 (0)