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 3b144a3

Browse filesBrowse files
committed
[Process] Return built-in cmd.exe commands directly in ExecutableFinder
1 parent 74fcbfa commit 3b144a3
Copy full SHA for 3b144a3

File tree

2 files changed

+24
-0
lines changed
Filter options

2 files changed

+24
-0
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Process/ExecutableFinder.php
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@
2020
class ExecutableFinder
2121
{
2222
private $suffixes = ['.exe', '.bat', '.cmd', '.com'];
23+
private const CMD_BUILTINS = [
24+
'assoc', 'break', 'call', 'cd', 'chdir', 'cls', 'color', 'copy', 'date',
25+
'del', 'dir', 'echo', 'endlocal', 'erase', 'exit', 'for', 'ftype', 'goto',
26+
'help', 'if', 'label', 'md', 'mkdir', 'mklink', 'move', 'path', 'pause',
27+
'popd', 'prompt', 'pushd', 'rd', 'rem', 'ren', 'rename', 'rmdir', 'set',
28+
'setlocal', 'shift', 'start', 'time', 'title', 'type', 'ver', 'vol',
29+
];
2330

2431
/**
2532
* Replaces default suffixes of executable.
@@ -48,6 +55,11 @@ public function addSuffix(string $suffix)
4855
*/
4956
public function find(string $name, ?string $default = null, array $extraDirs = [])
5057
{
58+
// windows built-in commands that are present in cmd.exe should not be resolved using PATH as they do not exist as exes
59+
if ('\\' === \DIRECTORY_SEPARATOR && \in_array(strtolower($name), self::CMD_BUILTINS, true)) {
60+
return $name;
61+
}
62+
5163
$dirs = array_merge(
5264
explode(\PATH_SEPARATOR, getenv('PATH') ?: getenv('Path')),
5365
$extraDirs

‎src/Symfony/Component/Process/Tests/ExecutableFinderTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Process/Tests/ExecutableFinderTest.php
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,18 @@ public function testEmptyDirInPath()
159159
unlink('executable');
160160
}
161161

162+
public function testFindBuiltInCommandOnWindows()
163+
{
164+
if ('\\' !== \DIRECTORY_SEPARATOR) {
165+
$this->markTestSkipped('Can be only tested on windows');
166+
}
167+
168+
$finder = new ExecutableFinder();
169+
$this->assertSame('rmdir', $finder->find('RMDIR'));
170+
$this->assertSame('cd', $finder->find('cd'));
171+
$this->assertSame('move', $finder->find('MoVe'));
172+
}
173+
162174
private function assertSamePath($expected, $tested)
163175
{
164176
if ('\\' === \DIRECTORY_SEPARATOR) {

0 commit comments

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