diff --git a/src/Settings.php b/src/Settings.php index 4622910..34d3ab2 100644 --- a/src/Settings.php +++ b/src/Settings.php @@ -130,7 +130,7 @@ public static function parseArguments(array $arguments) // Use the currently invoked php as the default if possible if (defined('PHP_BINARY')) { - $settings->phpExecutable = PHP_BINARY; + $settings->phpExecutable = self::escapeString(PHP_BINARY); } foreach ($arguments as $argument) { @@ -235,6 +235,24 @@ public static function getPathsFromStdIn() $lines = explode("\n", rtrim($content)); return array_map('rtrim', $lines); } + + /** + * @param string $path + * @param string $os + * @return string + */ + public static function escapeString(string $path, string $os = PHP_OS) + { + $path = trim($path); + + if (stripos(strtoupper($os), 'WIN') === 0) { + $path = str_replace('^\\', '\\', preg_replace('`(?syntaxErrorCallbackFile, $settings->syntaxErrorCallbackFile); } + + public function testEscapingPathForUnixSystems() + { + Settings::escapeString('path with spaces'); + + $php_path = "path with/spaces between/php.exe"; + Assert::equal(Settings::escapeString($php_path, 'Darwin'), "path\\ with/spaces\\ between/php.exe"); + } + + public function testEscapingPathForWindows() + { + Settings::escapeString('path with spaces'); + + $php_path = "path with\spaces between\php.exe"; + Assert::equal(Settings::escapeString($php_path, 'Windows'), 'path^ with\\\spaces^ between\\\php.exe'); + } + + public function testEscapingEmptyPath() + { + Assert::equal(Settings::escapeString(''), ''); + } + + public function testEscapingPathWithSpecialChars() + { + $path = "path/with/special&characters"; + + Assert::equal(Settings::escapeString($path), "path/with/special\&characters"); + } + + public function testEscapingPathWithLeadingTrailingSpaces() + { + $path = " path with\spaces "; + + Assert::equal(Settings::escapeString($path), "path\\ with\\\spaces"); + } } $testCase = new SettingsParseArgumentsTest;