From 3ae662f4c7be3f37aa8628d3540486ba79c1de94 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Wed, 7 Jun 2023 15:19:44 +0200 Subject: [PATCH] Fix EventDispatcher on windows picking bat files when using "@php binary", fixes #11490 --- src/Composer/EventDispatcher/EventDispatcher.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Composer/EventDispatcher/EventDispatcher.php b/src/Composer/EventDispatcher/EventDispatcher.php index 95ca80d20..b564cf367 100644 --- a/src/Composer/EventDispatcher/EventDispatcher.php +++ b/src/Composer/EventDispatcher/EventDispatcher.php @@ -351,6 +351,14 @@ class EventDispatcher if ($matched && !file_exists($match[0])) { $finder = new ExecutableFinder; if ($pathToExec = $finder->find($match[0])) { + if (Platform::isWindows()) { + $execWithoutExt = Preg::replace('{\.(exe|bat|cmd|com)$}i', '', $pathToExec); + // prefer non-extension file if it exists when executing with PHP + if (file_exists($execWithoutExt)) { + $pathToExec = $execWithoutExt; + } + unset($execWithoutExt); + } $pathAndArgs = $pathToExec . substr($pathAndArgs, strlen($match[0])); } }