diff --git a/src/Symfony/Component/AssetMapper/ImportMap/ImportMapManager.php b/src/Symfony/Component/AssetMapper/ImportMap/ImportMapManager.php index 1dbbf34d28d92..278d81e41c870 100644 --- a/src/Symfony/Component/AssetMapper/ImportMap/ImportMapManager.php +++ b/src/Symfony/Component/AssetMapper/ImportMap/ImportMapManager.php @@ -111,8 +111,8 @@ public function update(): array */ public static function parsePackageName(string $packageName): ?array { - // https://regex101.com/r/58bl9L/1 - $regex = '/(?:(?P[^:\n]+):)?(?P[^@\n]+)(?:@(?P[^\s\n]+))?/'; + // https://regex101.com/r/d99BEc/1 + $regex = '/(?:(?P[^:\n]+):)?((?P@?[^@\n]+))(?:@(?P[^\s\n]+))?/'; return preg_match($regex, $packageName, $matches) ? $matches : null; } diff --git a/src/Symfony/Component/AssetMapper/Tests/ImportMap/ImportMapManagerTest.php b/src/Symfony/Component/AssetMapper/Tests/ImportMap/ImportMapManagerTest.php index 4c75084c8681d..857d15e77d8d9 100644 --- a/src/Symfony/Component/AssetMapper/Tests/ImportMap/ImportMapManagerTest.php +++ b/src/Symfony/Component/AssetMapper/Tests/ImportMap/ImportMapManagerTest.php @@ -422,6 +422,40 @@ public static function getPackageNameTests(): iterable 'version' => '^1.2.3', ], ]; + + yield 'namespaced_package_simple' => [ + '@hotwired/stimulus', + [ + 'package' => '@hotwired/stimulus', + 'registry' => '', + ], + ]; + + yield 'namespaced_package_with_version_constraint' => [ + '@hotwired/stimulus@^1.2.3', + [ + 'package' => '@hotwired/stimulus', + 'registry' => '', + 'version' => '^1.2.3', + ], + ]; + + yield 'namespaced_package_with_registry' => [ + 'npm:@hotwired/stimulus', + [ + 'package' => '@hotwired/stimulus', + 'registry' => 'npm', + ], + ]; + + yield 'namespaced_package_with_registry_and_version' => [ + 'npm:@hotwired/stimulus@^1.2.3', + [ + 'package' => '@hotwired/stimulus', + 'registry' => 'npm', + 'version' => '^1.2.3', + ], + ]; } private function createImportMapManager(array $dirs, string $rootDir, string $publicPrefix = '/assets/', string $publicDirName = 'public'): ImportMapManager