Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 73140eb

Browse filesBrowse files
[Process] Properly deal with not-found executables on Windows
1 parent f41aa69 commit 73140eb
Copy full SHA for 73140eb

File tree

Expand file treeCollapse file tree

2 files changed

+18
-8
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+18
-8
lines changed

‎src/Symfony/Component/Process/ExecutableFinder.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Process/ExecutableFinder.php
+8-2Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,14 @@ public function find(string $name, ?string $default = null, array $extraDirs = [
7070
}
7171
}
7272

73-
$command = '\\' === \DIRECTORY_SEPARATOR ? 'where' : 'command -v --';
74-
if (\function_exists('exec') && ($executablePath = strtok(@exec($command.' '.escapeshellarg($name)), \PHP_EOL)) && @is_executable($executablePath)) {
73+
if (!\function_exists('exec') || \strlen($name) !== strcspn($name, '/'.\DIRECTORY_SEPARATOR)) {
74+
return $default;
75+
}
76+
77+
$command = '\\' === \DIRECTORY_SEPARATOR ? 'where %s 2> NUL' : 'command -v -- %s';
78+
$execResult = exec(\sprintf($command, escapeshellarg($name)));
79+
80+
if (($executablePath = substr($execResult, 0, strpos($execResult, \PHP_EOL) ?: null)) && @is_executable($executablePath)) {
7581
return $executablePath;
7682
}
7783

‎src/Symfony/Component/Process/PhpExecutableFinder.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Process/PhpExecutableFinder.php
+10-6Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,16 @@ public function find(bool $includeArgs = true)
3535
{
3636
if ($php = getenv('PHP_BINARY')) {
3737
if (!is_executable($php)) {
38-
$command = '\\' === \DIRECTORY_SEPARATOR ? 'where' : 'command -v --';
39-
if (\function_exists('exec') && $php = strtok(exec($command.' '.escapeshellarg($php)), \PHP_EOL)) {
40-
if (!is_executable($php)) {
41-
return false;
42-
}
43-
} else {
38+
if (!\function_exists('exec') || \strlen($php) !== strcspn($php, '/'.\DIRECTORY_SEPARATOR)) {
39+
return false;
40+
}
41+
42+
$command = '\\' === \DIRECTORY_SEPARATOR ? 'where %s 2> NUL' : 'command -v -- %s';
43+
$execResult = exec(\sprintf($command, escapeshellarg($php)));
44+
if (!$php = substr($execResult, 0, strpos($execResult, \PHP_EOL) ?: null)) {
45+
return false;
46+
}
47+
if (!is_executable($php)) {
4448
return false;
4549
}
4650
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.