Skip to content

Commit d296639

Browse files
committed
Fix platform inconsistency with empty values
An unexpected `false` or `null` value was handled inconsistently across platforms, returning an empty string on Windows, otherwise `''`. This is fixed to return `""` on Windows.
1 parent 9b76a6c commit d296639

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
composer.lock
22
phpcs.xml
33
phpunit.xml
4+
.phpunit.result.cache
45
vendor/
6+

src/Args.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public static function escape($arg, $meta = true, $module = false)
3939
}
4040

4141
// Check for whitespace or an empty value
42-
$quote = strpbrk($arg, " \t") !== false || $arg === '';
42+
$quote = strpbrk($arg, " \t") !== false || (string) $arg === '';
4343

4444
// Escape double-quotes and double-up preceding backslashes
4545
$arg = preg_replace('/(\\\\*)"/', '$1$1\\"', $arg, -1, $dquotes);

tests/ArgsTest.php

+17-2
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,22 @@ public function testCommandLine()
4949
}
5050

5151
$params = array(PHP_BINARY, __DIR__.DIRECTORY_SEPARATOR.'args.php');
52+
$args = array();
5253
$expected = array();
5354

5455
foreach ($this->dataArguments() as $test) {
55-
$expected[] = $test[0];
56+
$arg = $test[0];
57+
58+
if ($arg === null || $arg === false) {
59+
$expected[] = '';
60+
} else {
61+
$expected[] = $arg;
62+
}
63+
64+
$args[] = $arg;
5665
}
5766

58-
$params = array_merge($params, $expected);
67+
$params = array_merge($params, $args);
5968
$command = Args::escapeCommand($params);
6069

6170
exec($command, $lines);
@@ -74,6 +83,12 @@ public function dataArguments()
7483
// empty argument - must be quoted
7584
'empty' => array('', '""', "''", 0),
7685

86+
// false argument - must be quoted
87+
'empty false' => array(false, '""', "''", 0),
88+
89+
// null argument - must be quoted
90+
'empty null' => array(null, '""', "''", 0),
91+
7792
// unix single-quote must be escaped
7893
'unix-sq' => array("a'bc", "a'bc", "'a'\\''bc'", 0),
7994

0 commit comments

Comments
 (0)