Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# Auto detect text files and perform EOL normalization
* text=auto eol=lf
tests/data/*-win.php eol=crlf
4 changes: 2 additions & 2 deletions features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ private static function terminate_proc( $master_pid ) {

$output = `ps -o ppid,pid,command | grep $master_pid`;

foreach ( explode( PHP_EOL, $output ) as $line ) {
foreach ( explode( "\n", $output ) as $line ) {
if ( preg_match( '/^\s*(\d+)\s+(\d+)/', $line, $matches ) ) {
$parent = $matches[1];
$child = $matches[2];
Expand Down Expand Up @@ -393,7 +393,7 @@ public function move_files( $src, $dest ) {
public function add_line_to_wp_config( &$wp_config_code, $line ) {
$token = "/* That's all, stop editing!";

$wp_config_code = str_replace( $token, "$line\n\n$token", $wp_config_code );
$wp_config_code = str_replace( $token, $line. PHP_EOL . PHP_EOL . $token, $wp_config_code );
}

public function download_wp( $subdir = '' ) {
Expand Down
2 changes: 1 addition & 1 deletion features/bootstrap/support.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ function checkThatJsonStringContainsJsonString( $actualJson, $expectedJson ) {
* @return bool Whether $actualCSV contains $expectedCSV
*/
function checkThatCsvStringContainsValues( $actualCSV, $expectedCSV ) {
$actualCSV = array_map( 'str_getcsv', explode( PHP_EOL, $actualCSV ) );
$actualCSV = array_map( 'str_getcsv', explode( "\n", $actualCSV ) );

if ( empty( $actualCSV ) )
return false;
Expand Down
4 changes: 2 additions & 2 deletions features/steps/given.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function ( $world, $path, PyStringNode $content ) {
$content = (string) $content . "\n";
$full_path = $world->variables['RUN_DIR'] . "/$path";
Process::create( \WP_CLI\utils\esc_cmd( 'mkdir -p %s', dirname( $full_path ) ) )->run_check();
file_put_contents( $full_path, $content );
file_put_contents( $full_path, WP_CLI\Utils\denormalize_newlines( $content ) );
}
);

Expand Down Expand Up @@ -88,7 +88,7 @@ function ( $world, $type = 'subdirectory' ) {

$steps->Given( '/^these installed and active plugins:$/',
function( $world, $stream ) {
$plugins = implode( ' ', array_map( 'trim', explode( PHP_EOL, (string)$stream ) ) );
$plugins = implode( ' ', array_map( 'trim', explode( "\n", (string)$stream ) ) );
$world->proc( "wp plugin install $plugins --activate" )->run_check();
}
);
Expand Down
2 changes: 1 addition & 1 deletion features/steps/then.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ function ( $world, $path, $type, $action, $expected = null ) {
foreach( $files as &$file ) {
$file = str_replace( $path . '/', '', $file );
}
$contents = implode( PHP_EOL, $files );
$contents = implode( "\n", $files );
}
checkString( $contents, $expected, $action );
}
Expand Down
6 changes: 6 additions & 0 deletions features/steps/when.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ function ( $world, $cmd ) {
function ( $world, $mode, $cmd ) {
$cmd = $world->replace_variables( $cmd );
$world->result = invoke_proc( $world->proc( $cmd ), $mode );
$world->result->stdout = WP_CLI\Utils\normalize_newlines( $world->result->stdout );
$world->result->stderr = WP_CLI\Utils\normalize_newlines( $world->result->stderr );
list( $world->result->stdout, $world->email_sends ) = capture_email_sends( $world->result->stdout );
}
);
Expand All @@ -37,6 +39,8 @@ function ( $world, $mode, $cmd ) {
function ( $world, $mode, $cmd, $subdir ) {
$cmd = $world->replace_variables( $cmd );
$world->result = invoke_proc( $world->proc( $cmd, array(), $subdir ), $mode );
$world->result->stdout = WP_CLI\Utils\normalize_newlines( $world->result->stdout );
$world->result->stderr = WP_CLI\Utils\normalize_newlines( $world->result->stderr );
list( $world->result->stdout, $world->email_sends ) = capture_email_sends( $world->result->stdout );
}
);
Expand All @@ -48,6 +52,8 @@ function ( $world, $mode ) {

$proc = Process::create( $world->result->command, $world->result->cwd, $world->result->env );
$world->result = invoke_proc( $proc, $mode );
$world->result->stdout = WP_CLI\Utils\normalize_newlines( $world->result->stdout );
$world->result->stderr = WP_CLI\Utils\normalize_newlines( $world->result->stderr );
list( $world->result->stdout, $world->email_sends ) = capture_email_sends( $world->result->stdout );
}
);
Expand Down
2 changes: 1 addition & 1 deletion php/WP_CLI/Bootstrap/IncludeFrameworkAutoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ protected function get_autoloader_paths() {
protected function handle_failure() {
fputs(
STDERR,
"Internal error: Can't find Composer autoloader.\nTry running: composer install\n"
'Internal error: Can\'t find Composer autoloader.' . PHP_EOL . 'Try running: composer install' . PHP_EOL
);
exit( 3 );
}
Expand Down
2 changes: 1 addition & 1 deletion php/WP_CLI/Configurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ private function unmix_assoc_args( $mixed_args, $global_assoc = array(), $local_
private function assoc_arg_to_runtime_config( $key, $value, &$runtime_config ) {
$details = $this->spec[ $key ];
if ( isset( $details['deprecated'] ) ) {
fwrite( STDERR, "WP-CLI: The --{$key} global parameter is deprecated. {$details['deprecated']}\n" );
fwrite( STDERR, "WP-CLI: The --{$key} global parameter is deprecated. {$details['deprecated']}" . PHP_EOL );
}

if ( $details['multiple'] ) {
Expand Down
8 changes: 4 additions & 4 deletions php/WP_CLI/Dispatcher/Subcommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function __construct( $parent, $name, $docparser, $when_invoked ) {
* @return string
*/
private static function extract_synopsis( $longdesc ) {
preg_match_all( '/(.+?)[\r\n]+:/', $longdesc, $matches );
preg_match_all( '/(.+?)\n+:/', $longdesc, $matches );
return implode( ' ', $matches[1] );
}

Expand Down Expand Up @@ -276,8 +276,8 @@ private function validate_args( $args, $assoc_args, $extra_args ) {
$i = 0;
$errors = array( 'fatal' => array(), 'warning' => array() );
$mock_doc = array( $this->get_shortdesc(), '' );
$mock_doc = array_merge( $mock_doc, explode( PHP_EOL, $this->get_longdesc() ) );
$mock_doc = '/**' . PHP_EOL . '* ' . implode( PHP_EOL . '* ', $mock_doc ) . PHP_EOL . '*/';
$mock_doc = array_merge( $mock_doc, explode( "\n", $this->get_longdesc() ) );
$mock_doc = "/**\n* " . implode( "\n* ", $mock_doc ) . "\n*/";
$docparser = new \WP_CLI\DocParser( $mock_doc );
foreach( $synopsis_spec as $spec ) {
if ( 'positional' === $spec['type'] ) {
Expand Down Expand Up @@ -335,7 +335,7 @@ private function validate_args( $args, $assoc_args, $extra_args ) {
$errors['fatal'][] = sprintf(
'unknown --%s parameter%s',
$key,
! empty( $suggestion ) ? PHP_EOL . "Did you mean '--{$suggestion}'?" : ''
! empty( $suggestion ) ? "\nDid you mean '--{$suggestion}'?" : ''
);
}
}
Expand Down
7 changes: 4 additions & 3 deletions php/WP_CLI/DocParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class DocParser {
* @param string $docComment
*/
public function __construct( $docComment ) {
$docComment = Utils\normalize_newlines( $docComment );
$this->docComment = self::remove_decorations( $docComment );
}

Expand All @@ -29,7 +30,7 @@ public function __construct( $docComment ) {
* @return string
*/
private static function remove_decorations( $comment ) {
$comment = preg_replace( '|^/\*\*[\r\n]+|', '', $comment );
$comment = preg_replace( '|^/\*\*\n+|', '', $comment );
$comment = preg_replace( '|\n[\t ]*\*/$|', '', $comment );
$comment = preg_replace( '|^[\t ]*\* ?|m', '', $comment );

Expand Down Expand Up @@ -155,7 +156,7 @@ public function get_param_args( $key ) {
* @return array|null Interpreted YAML document, or null.
*/
private function get_arg_or_param_args( $regex ) {
$bits = explode( PHP_EOL, $this->docComment );
$bits = explode( "\n", $this->docComment );
$within_arg = $within_doc = false;
$document = array();
foreach( $bits as $bit ) {
Expand All @@ -182,7 +183,7 @@ private function get_arg_or_param_args( $regex ) {
}

if ( $document ) {
return Spyc::YAMLLoadString( implode( PHP_EOL, $document ) );
return Spyc::YAMLLoadString( implode( "\n", $document ) );
}
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion php/WP_CLI/Loggers/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function debug( $message, $group = false ) {
* @param string $str Message to write.
*/
protected function write( $handle, $str ) {
fwrite( $handle, $str );
fwrite( $handle, \WP_CLI\Utils\denormalize_newlines( $str ) );
}

/**
Expand Down
6 changes: 3 additions & 3 deletions php/WP_CLI/ProcessRun.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ public function __construct( $props ) {
* @return string
*/
public function __toString() {
$out = "$ $this->command\n";
$out .= "$this->stdout\n$this->stderr";
$out .= "cwd: $this->cwd\n";
$out = "$ $this->command" . PHP_EOL;
$out .= Utils\denormalize_newlines( $this->stdout ) . PHP_EOL . Utils\denormalize_newlines( $this->stderr );
$out .= "cwd: $this->cwd" . PHP_EOL;
$out .= "exit status: $this->return_code";

return $out;
Expand Down
8 changes: 4 additions & 4 deletions php/WP_CLI/Runner.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,14 +267,14 @@ public function find_command_to_run( $args ) {
$child,
$parent_name,
$parent_name,
! empty( $suggestion ) ? PHP_EOL . "Did you mean '{$suggestion}'?" : ''
! empty( $suggestion ) ? "\nDid you mean '{$suggestion}'?" : ''
);
} else {
$suggestion = $this->get_subcommand_suggestion( $full_name, $command );
return sprintf(
"'%s' is not a registered wp command. See 'wp help'.%s",
$full_name,
! empty( $suggestion ) ? PHP_EOL . "Did you mean '{$suggestion}'?" : ''
! empty( $suggestion ) ? "\nDid you mean '{$suggestion}'?" : ''
);
}
}
Expand Down Expand Up @@ -430,7 +430,7 @@ public function is_command_disabled( $command ) {
public function get_wp_config_code() {
$wp_config_path = Utils\locate_wp_config();

$wp_config_code = explode( "\n", file_get_contents( $wp_config_path ) );
$wp_config_code = explode( "\n", Utils\normalize_newlines( file_get_contents( $wp_config_path ) ) );

$found_wp_settings = false;

Expand Down Expand Up @@ -804,7 +804,7 @@ public function start() {
$error_msg = "Alias '{$this->alias}' not found.";
$suggestion = Utils\get_suggestion( $this->alias, array_keys( $this->aliases ), $threshold = 2 );
if ( $suggestion ) {
$error_msg .= PHP_EOL . "Did you mean '{$suggestion}'?";
$error_msg .= "\nDid you mean '{$suggestion}'?";
}
WP_CLI::error( $error_msg );
}
Expand Down
4 changes: 2 additions & 2 deletions php/boot-fs.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
// This file needs to parse without error in PHP < 5.3

if ( 'cli' !== PHP_SAPI ) {
echo "Only CLI access.\n";
echo 'Only CLI access.' . PHP_EOL;
die(-1);
}

if ( version_compare( PHP_VERSION, '5.3.0', '<' ) ) {
printf( "Error: WP-CLI requires PHP %s or newer. You are running version %s.\n", '5.3.0', PHP_VERSION );
printf( 'Error: WP-CLI requires PHP %s or newer. You are running version %s.' . PHP_EOL, '5.3.0', PHP_VERSION );
die(-1);
}

Expand Down
16 changes: 8 additions & 8 deletions php/class-wp-cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -488,9 +488,9 @@ public static function add_command( $name, $callable, $args = array() ) {
$long_desc = '';
$bits = explode( ' ', $synopsis );
foreach( $args['synopsis'] as $key => $arg ) {
$long_desc .= $bits[ $key ] . PHP_EOL;
$long_desc .= $bits[ $key ] . "\n";
if ( ! empty( $arg['description'] ) ) {
$long_desc .= ': ' . $arg['description'] . PHP_EOL;
$long_desc .= ': ' . $arg['description'] . "\n";
}
$yamlify = array();
foreach( array( 'default', 'options' ) as $key ) {
Expand All @@ -500,13 +500,13 @@ public static function add_command( $name, $callable, $args = array() ) {
}
if ( ! empty( $yamlify ) ) {
$long_desc .= Spyc::YAMLDump( $yamlify );
$long_desc .= '---' . PHP_EOL;
$long_desc .= '---' . "\n";
}
$long_desc .= PHP_EOL;
$long_desc .= "\n";
}
if ( ! empty( $long_desc ) ) {
$long_desc = rtrim( $long_desc, PHP_EOL );
$long_desc = '## OPTIONS' . PHP_EOL . PHP_EOL . $long_desc;
$long_desc = rtrim( $long_desc, "\n" );
$long_desc = '## OPTIONS' . "\n\n" . $long_desc;
$leaf_command->set_longdesc( $long_desc );
}
}
Expand Down Expand Up @@ -587,7 +587,7 @@ public static function remove_deferred_addition( $name ) {
* @return null
*/
public static function line( $message = '' ) {
echo $message . "\n";
echo Utils\denormalize_newlines( $message . "\n" );
}

/**
Expand Down Expand Up @@ -862,7 +862,7 @@ public static function print_value( $value, $assoc_args = array() ) {
$value = var_export( $value );
}

echo $value . "\n";
echo Utils\denormalize_newlines( $value . "\n" );
}

/**
Expand Down
1 change: 1 addition & 0 deletions php/commands/help.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ private static function show_help( $command ) {
// section headers
$out = preg_replace( '/^## ([A-Z ]+)/m', WP_CLI::colorize( '%9\1%n' ), $out );

$out = Utils\denormalize_newlines( $out );
self::pass_through_pager( $out );
}

Expand Down
2 changes: 1 addition & 1 deletion php/commands/src/CLI_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ public function update( $_, $assoc_args ) {
$process = WP_CLI\Process::create( "{$php_binary} $temp --info {$allow_root}" );
$result = $process->run();
if ( 0 !== $result->return_code || false === stripos( $result->stdout, 'WP-CLI version:' ) ) {
$multi_line = explode( PHP_EOL, $result->stderr );
$multi_line = explode( "\n", Utils\normalize_newlines( $result->stderr ) );
WP_CLI::error_multi_line( $multi_line );
WP_CLI::error( 'The downloaded PHAR is broken, try running wp cli update again.' );
}
Expand Down
27 changes: 26 additions & 1 deletion php/utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function load_dependencies() {
}

if ( !$has_autoload ) {
fputs( STDERR, "Internal error: Can't find Composer autoloader.\nTry running: composer install\n" );
fputs( STDERR, 'Internal error: Can\'t find Composer autoloader.' . PHP_EOL . 'Try running: composer install' . PHP_EOL );
exit(3);
}
}
Expand Down Expand Up @@ -1023,3 +1023,28 @@ function force_env_on_nix_systems( $command ) {
}
return $command;
}

/**
* Normalize Windows newlines to Unix ones.
*
* @param string $str
*
* @return string
*/
function normalize_newlines( $str ) {
return str_replace( "\r\n", "\n", $str );
}

/**
* Denormalize Unix newlines to Windows ones if on Windows.
*
* @param string $str
*
* @return string
*/
function denormalize_newlines( $str ) {
if ( is_windows() ) {
return preg_replace( '/(?<!\r)\n/', "\r\n", $str );
}
return $str;
}
Loading