From 98f6969e9c2ebbb00d81bf9362f072cb200da38a Mon Sep 17 00:00:00 2001 From: Helmer Aaviksoo Date: Thu, 8 Aug 2013 01:27:53 +0300 Subject: [PATCH] Fix empty process argument escaping on Windows --- src/Symfony/Component/Process/ProcessUtils.php | 8 ++++++-- src/Symfony/Component/Process/Tests/ProcessUtilsTest.php | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Process/ProcessUtils.php b/src/Symfony/Component/Process/ProcessUtils.php index 42ed342afd83..4a5b7d60731a 100644 --- a/src/Symfony/Component/Process/ProcessUtils.php +++ b/src/Symfony/Component/Process/ProcessUtils.php @@ -41,11 +41,15 @@ public static function escapeArgument($argument) //@see https://bugs.php.net/bug.php?id=43784 //@see https://bugs.php.net/bug.php?id=49446 if (defined('PHP_WINDOWS_VERSION_BUILD')) { + if ('' === $argument) { + return escapeshellarg($argument); + } + $escapedArgument = ''; foreach (preg_split('/([%"])/i', $argument, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE) as $part) { - if ('"' == $part) { + if ('"' === $part) { $escapedArgument .= '\\"'; - } elseif ('%' == $part) { + } elseif ('%' === $part) { $escapedArgument .= '^%'; } else { $escapedArgument .= escapeshellarg($part); diff --git a/src/Symfony/Component/Process/Tests/ProcessUtilsTest.php b/src/Symfony/Component/Process/Tests/ProcessUtilsTest.php index e51da5a5e22a..603fac53e787 100644 --- a/src/Symfony/Component/Process/Tests/ProcessUtilsTest.php +++ b/src/Symfony/Component/Process/Tests/ProcessUtilsTest.php @@ -30,6 +30,7 @@ public function dataArguments() array('"foo bar"', 'foo bar'), array('^%"path"^%', '%path%'), array('"<|>"\\"" "\\""\'f"', '<|>" "\'f'), + array('""', ''), ); } @@ -37,6 +38,7 @@ public function dataArguments() array("'foo bar'", 'foo bar'), array("'%path%'", '%path%'), array("'<|>\" \"'\\''f'", '<|>" "\'f'), + array("''", ''), ); } }