From 62b97c9b048d450e1066cecec67dfe51d9febc7c Mon Sep 17 00:00:00 2001 From: scribu Date: Mon, 29 Apr 2013 19:38:51 +0300 Subject: [PATCH] rename create_cmd() to esc_cmd() Matches WP escaping functions: esc_sql(), esc_html() etc. --- features/bootstrap/FeatureContext.php | 6 +++--- php/commands/core.php | 2 +- php/commands/db.php | 10 +++++----- php/utils.php | 7 +++++-- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/features/bootstrap/FeatureContext.php b/features/bootstrap/FeatureContext.php index fd2fdf2d..19b7025c 100644 --- a/features/bootstrap/FeatureContext.php +++ b/features/bootstrap/FeatureContext.php @@ -94,14 +94,14 @@ class FeatureContext extends BehatContext implements ClosuredContextInterface { if ( !$path ) { $path = sys_get_temp_dir() . '/wp-cli-test-cache'; - system( Utils\create_cmd( 'mkdir -p %s', $path ) ); + system( Utils\esc_cmd( 'mkdir -p %s', $path ) ); } return $path . '/' . $file; } public function download_file( $url, $path ) { - system( Utils\create_cmd( 'curl -sSL %s > %s', $url, $path ) ); + system( Utils\esc_cmd( 'curl -sSL %s > %s', $url, $path ) ); } private static function run_sql( $sql ) { @@ -187,7 +187,7 @@ class FeatureContext extends BehatContext implements ClosuredContextInterface { if ( $subdir ) mkdir( $dest_dir ); - $cmd = Utils\create_cmd( "cp -r %s/* %s", $cache_dir, $dest_dir ); + $cmd = Utils\esc_cmd( "cp -r %s/* %s", $cache_dir, $dest_dir ); system( $cmd ); } diff --git a/php/commands/core.php b/php/commands/core.php index e62a2ea6..3c3724ab 100644 --- a/php/commands/core.php +++ b/php/commands/core.php @@ -39,7 +39,7 @@ class Core_Command extends WP_CLI_Command { $silent = WP_CLI::get_config('quiet') ? '--silent ' : ''; $cmd = "curl -f $silent %s | tar xz --strip-components=1 --directory=%s"; - WP_CLI::launch( Utils\create_cmd( $cmd, $download_url, ABSPATH ) ); + WP_CLI::launch( Utils\esc_cmd( $cmd, $download_url, ABSPATH ) ); WP_CLI::success( 'WordPress downloaded.' ); } diff --git a/php/commands/db.php b/php/commands/db.php index c411413a..a14c286f 100644 --- a/php/commands/db.php +++ b/php/commands/db.php @@ -49,7 +49,7 @@ class DB_Command extends WP_CLI_Command { * Optimize the database. */ function optimize() { - self::run( 'mysqlcheck', Utils\create_cmd( + self::run( 'mysqlcheck', Utils\esc_cmd( '--optimize --host=%s --user=%s %s', DB_HOST, DB_USER, DB_NAME ) ); @@ -61,7 +61,7 @@ class DB_Command extends WP_CLI_Command { * Repair the database. */ function repair() { - self::run( 'mysqlcheck', Utils\create_cmd( + self::run( 'mysqlcheck', Utils\esc_cmd( '--repair --host=%s --user=%s %s', DB_HOST, DB_USER, DB_NAME ) ); @@ -74,7 +74,7 @@ class DB_Command extends WP_CLI_Command { * @alias connect */ function cli() { - self::run( 'mysql', Utils\create_cmd( + self::run( 'mysql', Utils\esc_cmd( '--host=%s --user=%s --database=%s', DB_HOST, DB_USER, DB_NAME ) ); } @@ -100,7 +100,7 @@ class DB_Command extends WP_CLI_Command { function export( $args, $assoc_args ) { $result_file = $this->get_file_name( $args ); - self::run( 'mysqldump', Utils\create_cmd( + self::run( 'mysqldump', Utils\esc_cmd( '%s --user=%s --host=%s --result-file %s', DB_NAME, DB_USER, DB_HOST, $result_file ) ); @@ -115,7 +115,7 @@ class DB_Command extends WP_CLI_Command { function import( $args, $assoc_args ) { $result_file = $this->get_file_name( $args ); - self::run( 'mysql', Utils\create_cmd( + self::run( 'mysql', Utils\esc_cmd( '%s --user=%s --host=%s < %s', DB_NAME, DB_USER, DB_HOST, $result_file ) ); diff --git a/php/utils.php b/php/utils.php index 3489393d..3521a2a6 100644 --- a/php/utils.php +++ b/php/utils.php @@ -138,7 +138,10 @@ function assoc_args_to_str( $assoc_args ) { * Given a template string and an arbitrary number of arguments, * returns the final command, with the parameters escaped. */ -function create_cmd( $cmd ) { +function esc_cmd( $cmd ) { + if ( func_num_args() < 2 ) + trigger_error( 'esc_cmd() requires at least two arguments.', E_USER_WARNING ); + $args = func_get_args(); $cmd = array_shift( $args ); @@ -368,7 +371,7 @@ function find_subcommand( $args ) { function run_mysql_query( $query, $args ) { // TODO: use PDO? - $arg_str = create_cmd( '--host=%s --user=%s --execute=%s', + $arg_str = esc_cmd( '--host=%s --user=%s --execute=%s', $args['host'], $args['user'], $query ); run_mysql_command( 'mysql', $arg_str, $args['pass'] ); -- 2.11.0