From 3ba58ea3eb651dafa06bb69b2c6cb3a708d9b762 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Mon, 19 Aug 2024 13:52:44 +0200 Subject: [PATCH] Normalize namespaces in psr-0/psr-4 rules to fix edge cases, fixes #12028 (#12063) --- src/Composer/Autoload/AutoloadGenerator.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Composer/Autoload/AutoloadGenerator.php b/src/Composer/Autoload/AutoloadGenerator.php index 9da1767ad..2d4bfd265 100644 --- a/src/Composer/Autoload/AutoloadGenerator.php +++ b/src/Composer/Autoload/AutoloadGenerator.php @@ -1241,6 +1241,10 @@ INITIALIZER; } foreach ($autoload[$type] as $namespace => $paths) { + if (in_array($type, ['psr-4', 'psr-0'], true)) { + // normalize namespaces to ensure "\" becomes "" and others do not have leading separators as they are not needed + $namespace = ltrim($namespace, '\\'); + } foreach ((array) $paths as $path) { if (($type === 'files' || $type === 'classmap' || $type === 'exclude-from-classmap') && $package->getTargetDir() && !Filesystem::isReadable($installPath.'/'.$path)) { // remove target-dir from file paths of the root package