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

[Process] Return built-in cmd.exe commands directly in ExecutableFinder #58735

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[Process] Return built-in cmd.exe commands directly in ExecutableFinder
  • Loading branch information
Seldaek committed Nov 2, 2024
commit 3b144a3a243aef35365cf578f5ac2875b68dcc48
12 changes: 12 additions & 0 deletions 12 src/Symfony/Component/Process/ExecutableFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@
class ExecutableFinder
{
private $suffixes = ['.exe', '.bat', '.cmd', '.com'];
private const CMD_BUILTINS = [
'assoc', 'break', 'call', 'cd', 'chdir', 'cls', 'color', 'copy', 'date',
'del', 'dir', 'echo', 'endlocal', 'erase', 'exit', 'for', 'ftype', 'goto',
'help', 'if', 'label', 'md', 'mkdir', 'mklink', 'move', 'path', 'pause',
'popd', 'prompt', 'pushd', 'rd', 'rem', 'ren', 'rename', 'rmdir', 'set',
'setlocal', 'shift', 'start', 'time', 'title', 'type', 'ver', 'vol',
];

/**
* Replaces default suffixes of executable.
Expand Down Expand Up @@ -48,6 +55,11 @@ public function addSuffix(string $suffix)
*/
public function find(string $name, ?string $default = null, array $extraDirs = [])
{
// windows built-in commands that are present in cmd.exe should not be resolved using PATH as they do not exist as exes
if ('\\' === \DIRECTORY_SEPARATOR && \in_array(strtolower($name), self::CMD_BUILTINS, true)) {
return $name;
}

$dirs = array_merge(
explode(\PATH_SEPARATOR, getenv('PATH') ?: getenv('Path')),
$extraDirs
Expand Down
12 changes: 12 additions & 0 deletions 12 src/Symfony/Component/Process/Tests/ExecutableFinderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,18 @@ public function testEmptyDirInPath()
unlink('executable');
}

public function testFindBuiltInCommandOnWindows()
{
if ('\\' !== \DIRECTORY_SEPARATOR) {
$this->markTestSkipped('Can be only tested on windows');
}

$finder = new ExecutableFinder();
$this->assertSame('rmdir', $finder->find('RMDIR'));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AppVeyor returns RMDIR but not rmdir (see the failing test). Do we need to fix the expectation here or is there still some flaw in the code?

Copy link
Member Author

@Seldaek Seldaek Nov 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the command names are case insensitive so I guess the implementation is fine but test expectations should be fixed to match the input's case.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 thanks for the feedback (see #58748 then)

$this->assertSame('cd', $finder->find('cd'));
$this->assertSame('move', $finder->find('MoVe'));
}

private function assertSamePath($expected, $tested)
{
if ('\\' === \DIRECTORY_SEPARATOR) {
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.