Skip to content

Commit 2cbd22c

Browse files
committed
Fix bug in user import-csv STDIN detection
1 parent cb5459b commit 2cbd22c

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

src/WP_CLI/Entity/Utils.php

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,25 @@ class Utils {
1010
* @return bool
1111
*/
1212
public static function has_stdin() {
13-
$handle = fopen( 'php://stdin', 'r' );
14-
$read = array( $handle );
15-
$write = null;
16-
$except = null;
13+
$handle = fopen( 'php://stdin', 'r' );
14+
$read = array( $handle );
15+
$write = null;
16+
$except = null;
1717
$streams = stream_select( $read, $write, $except, 0 );
18+
$fstat = fstat( $handle );
19+
1820
fclose( $handle );
1921

20-
return 1 === $streams;
22+
if ( $streams !== 1 ) {
23+
// No stream on STDIN.
24+
return false;
25+
}
26+
27+
if ( isset( $fstat['size'] ) && $fstat['size'] === 0 ) {
28+
// A stream on STDIN was detected but has a size of 0 bytes.
29+
return false;
30+
}
31+
32+
return true;
2133
}
2234
}

0 commit comments

Comments
 (0)