Skip to content

Commit e2d11b6

Browse files
[Process] Fix handling empty path found in the PATH env var with ExecutableFinder
1 parent 95f3f19 commit e2d11b6

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

ExecutableFinder.php

+3
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ public function find(string $name, ?string $default = null, array $extraDirs = [
6060
}
6161
foreach ($suffixes as $suffix) {
6262
foreach ($dirs as $dir) {
63+
if ('' === $dir) {
64+
$dir = '.';
65+
}
6366
if (@is_file($file = $dir.\DIRECTORY_SEPARATOR.$name.$suffix) && ('\\' === \DIRECTORY_SEPARATOR || @is_executable($file))) {
6467
return $file;
6568
}

Tests/ExecutableFinderTest.php

+21
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ public function testFindWithOpenBaseDir()
111111
}
112112
}
113113

114+
/**
115+
* @runInSeparateProcess
116+
*/
114117
public function testFindBatchExecutableOnWindows()
115118
{
116119
if (\ini_get('open_basedir')) {
@@ -138,6 +141,24 @@ public function testFindBatchExecutableOnWindows()
138141
$this->assertSamePath($target.'.BAT', $result);
139142
}
140143

144+
/**
145+
* @runInSeparateProcess
146+
*/
147+
public function testEmptyDirInPath()
148+
{
149+
putenv(sprintf('PATH=%s:', \dirname(\PHP_BINARY)));
150+
151+
touch('executable');
152+
chmod('executable', 0700);
153+
154+
$finder = new ExecutableFinder();
155+
$result = $finder->find('executable');
156+
157+
$this->assertSame('./executable', $result);
158+
159+
unlink('executable');
160+
}
161+
141162
private function assertSamePath($expected, $tested)
142163
{
143164
if ('\\' === \DIRECTORY_SEPARATOR) {

0 commit comments

Comments
 (0)