diff --git a/features/scaffold.feature b/features/scaffold.feature index 652dc5d9..2cf2b0a5 100644 --- a/features/scaffold.feature +++ b/features/scaffold.feature @@ -116,6 +116,16 @@ Feature: WordPress code scaffolding """ And the return code should be 1 + @theme + Scenario: Scaffold a child theme with a relative --path argument containing '..' + Given a WP install in 'subdir' + And I run `wp --path=.. theme path` from 'subdir/wp-content' + And save STDOUT as {THEME_DIR} + + When I run `wp scaffold child-theme zombieland --parent_theme=umbrella --path=..` from 'subdir/wp-content' + Then the {THEME_DIR}/zombieland/style.css file should exist + And the {THEME_DIR}/zombieland/functions.php file should exist + @theme Scenario: Scaffold a child theme with dots in the slug Given a WP install diff --git a/src/Scaffold_Command.php b/src/Scaffold_Command.php index 448589e8..f1a3e6be 100644 --- a/src/Scaffold_Command.php +++ b/src/Scaffold_Command.php @@ -986,12 +986,14 @@ static function ( $item ) use ( $slug ) { private function check_target_directory( $type, $target_dir ) { $parent_dir = dirname( self::canonicalize_path( str_replace( '\\', '/', $target_dir ) ) ); - if ( 'theme' === $type && str_replace( '\\', '/', WP_CONTENT_DIR . '/themes' ) !== $parent_dir ) { - return sprintf( 'The target directory \'%1$s\' is not in \'%2$s\'.', $target_dir, WP_CONTENT_DIR . '/themes' ); + $themes_dir = self::canonicalize_path( str_replace( '\\', '/', WP_CONTENT_DIR . '/themes' ) ); + if ( 'theme' === $type && $themes_dir !== $parent_dir ) { + return sprintf( 'The target directory \'%1$s\' is not in \'%2$s\'.', $target_dir, $themes_dir ); } - if ( 'plugin' === $type && str_replace( '\\', '/', WP_PLUGIN_DIR ) !== $parent_dir ) { - return sprintf( 'The target directory \'%1$s\' is not in \'%2$s\'.', $target_dir, WP_PLUGIN_DIR ); + $plugins_dir = self::canonicalize_path( str_replace( '\\', '/', WP_PLUGIN_DIR ) ); + if ( 'plugin' === $type && $plugins_dir !== $parent_dir ) { + return sprintf( 'The target directory \'%1$s\' is not in \'%2$s\'.', $target_dir, $plugins_dir ); } // Success.