aboutsummaryrefslogtreecommitdiffstats
path: root/includes/shell/Shell.php
diff options
context:
space:
mode:
authorMax Semenik <maxsem.wiki@gmail.com>2017-11-28 18:51:25 -0800
committerMax Semenik <maxsem.wiki@gmail.com>2017-11-29 12:38:35 -0800
commit36009e3ca78cb92914e72a59633ea219d601fc4f (patch)
tree6d2e3874ec3ed18e5956c3604fac569b3c9ea584 /includes/shell/Shell.php
parent70a602dde40e3694f8ef8b9c779a528c17a48f42 (diff)
downloadmediawikicore-36009e3ca78cb92914e72a59633ea219d601fc4f.tar.gz
mediawikicore-36009e3ca78cb92914e72a59633ea219d601fc4f.zip
Shell: skip null parameters
Right now they're treated as empty strings, however this doesn't allow skipping parameters in the middle like $params = [ 'foo', $x ? '--bar' : null, '--baz', ]; In some cases this matters, e.g. `ls` works while `ls ''` doesn't. Also, fix spacing problems the new tests uncovered: * Extra space when using params() * Missing space when combining params() and unsafeParams() Change-Id: Icb29d4c48ae7f92fb5635e3865346c98f47abb01
Diffstat (limited to 'includes/shell/Shell.php')
-rw-r--r--includes/shell/Shell.php5
1 files changed, 4 insertions, 1 deletions
diff --git a/includes/shell/Shell.php b/includes/shell/Shell.php
index 6e4fd02a13b9..084e10e79352 100644
--- a/includes/shell/Shell.php
+++ b/includes/shell/Shell.php
@@ -142,7 +142,7 @@ class Shell {
* PHP 5.2.6+ (bug backported to earlier distro releases of PHP).
*
* @param string $args,... strings to escape and glue together, or a single array of
- * strings parameter
+ * strings parameter. Null values are ignored.
* @return string
*/
public static function escape( /* ... */ ) {
@@ -156,6 +156,9 @@ class Shell {
$first = true;
$retVal = '';
foreach ( $args as $arg ) {
+ if ( $arg === null ) {
+ continue;
+ }
if ( !$first ) {
$retVal .= ' ';
} else {