@@ -24,7 +24,7 @@ function extract_from_phar( $path ) {
24
24
25
25
$ fname = basename ( $ path );
26
26
27
- $ tmp_path = get_temp_dir () . " wp-cli- $ fname " ;
27
+ $ tmp_path = get_temp_dir () . uniqid ( ' wp-cli-extract-from-phar- ' , true ) . " - $ fname " ;
28
28
29
29
copy ( $ path , $ tmp_path );
30
30
@@ -351,19 +351,21 @@ function pick_fields( $item, $fields ) {
351
351
* @category Input
352
352
*
353
353
* @param string $content Some form of text to edit (e.g. post content)
354
+ * @param string $title Title to display in the editor.
355
+ * @param string $ext Extension to use with the temp file.
354
356
* @return string|bool Edited text, if file is saved from editor; false, if no change to file.
355
357
*/
356
- function launch_editor_for_input ( $ input , $ filename = 'WP-CLI ' ) {
358
+ function launch_editor_for_input ( $ input , $ title = 'WP-CLI ' , $ ext = ' tmp ' ) {
357
359
358
360
check_proc_available ( 'launch_editor_for_input ' );
359
361
360
362
$ tmpdir = get_temp_dir ();
361
363
362
364
do {
363
- $ tmpfile = basename ( $ filename );
365
+ $ tmpfile = basename ( $ title );
364
366
$ tmpfile = preg_replace ( '|\.[^.]*$| ' , '' , $ tmpfile );
365
367
$ tmpfile .= '- ' . substr ( md5 ( mt_rand () ), 0 , 6 );
366
- $ tmpfile = $ tmpdir . $ tmpfile . '.tmp ' ;
368
+ $ tmpfile = $ tmpdir . $ tmpfile . '. ' . $ ext ;
367
369
$ fp = fopen ( $ tmpfile , 'xb ' );
368
370
if ( ! $ fp && is_writable ( $ tmpdir ) && file_exists ( $ tmpfile ) ) {
369
371
$ tmpfile = '' ;
@@ -772,6 +774,31 @@ function trailingslashit( $string ) {
772
774
return rtrim ( $ string , '/ \\' ) . '/ ' ;
773
775
}
774
776
777
+ /**
778
+ * Normalize a filesystem path.
779
+ *
780
+ * On Windows systems, replaces backslashes with forward slashes
781
+ * and forces upper-case drive letters.
782
+ * Allows for two leading slashes for Windows network shares, but
783
+ * ensures that all other duplicate slashes are reduced to a single one.
784
+ * Ensures upper-case drive letters on Windows systems.
785
+ *
786
+ * @access public
787
+ * @category System
788
+ *
789
+ * @param string $path Path to normalize.
790
+ * @return string Normalized path.
791
+ */
792
+ function normalize_path ( $ path ) {
793
+ $ path = str_replace ( '\\' , '/ ' , $ path );
794
+ $ path = preg_replace ( '|(?<=.)/+| ' , '/ ' , $ path );
795
+ if ( ': ' === substr ( $ path , 1 , 1 ) ) {
796
+ $ path = ucfirst ( $ path );
797
+ }
798
+ return $ path ;
799
+ }
800
+
801
+
775
802
/**
776
803
* Convert Windows EOLs to *nix.
777
804
*
@@ -1307,6 +1334,7 @@ function get_php_binary() {
1307
1334
1308
1335
// Available since PHP 5.4.
1309
1336
if ( defined ( 'PHP_BINARY ' ) ) {
1337
+ // @codingStandardsIgnoreLine
1310
1338
return PHP_BINARY ;
1311
1339
}
1312
1340
0 commit comments