From b2c0dac2995120324cf121a91523f8964d894ed2 Mon Sep 17 00:00:00 2001 From: Dan Wallis Date: Thu, 24 Oct 2024 23:58:18 +0100 Subject: [PATCH] Normalise extension requirements --- src/Vendor/Composer/PackageHashNormalizer.php | 35 +++++++++++++++++++ .../No/Extension/normalized.json | 6 ++++ .../No/Extension/original.json | 11 ++++++ 3 files changed, 52 insertions(+) create mode 100644 test/Template/Vendor/Composer/ComposerJsonNormalizer/NormalizeNormalizesJson/Json/IsObject/HasEntries/Yes/HasProperty/ValueContainsPackagesAndVersionConstraints/HasEntries/Yes/HasNormalizedVersionConstraints/No/Extension/normalized.json create mode 100644 test/Template/Vendor/Composer/ComposerJsonNormalizer/NormalizeNormalizesJson/Json/IsObject/HasEntries/Yes/HasProperty/ValueContainsPackagesAndVersionConstraints/HasEntries/Yes/HasNormalizedVersionConstraints/No/Extension/original.json diff --git a/src/Vendor/Composer/PackageHashNormalizer.php b/src/Vendor/Composer/PackageHashNormalizer.php index c35c2d6a..bcb50649 100644 --- a/src/Vendor/Composer/PackageHashNormalizer.php +++ b/src/Vendor/Composer/PackageHashNormalizer.php @@ -57,6 +57,7 @@ public function normalize(Json $json): Json continue; } + $packages = self::mergeDuplicateExtensions($packages); $decoded->{$name} = self::sortPackages($packages); } @@ -114,4 +115,38 @@ private static function sortPackages(array $packages): array return $packages; } + + /** + * This code is adopted from composer/composer (originally licensed under MIT by Nils Adermann + * and Jordi Boggiano ). + * + * @see https://github.com/composer/composer/blob/2.8.1/src/Composer/Repository/PlatformRepository.php#L682 + * + * @param array $packages + * + * @return array + */ + private static function mergeDuplicateExtensions($packages): array + { + foreach ($packages as $name => $value) { + if (!isset($name[4]) || \strtolower(\substr($name, 0, 4)) !== 'ext-') { + continue; + } + + $newName = \str_replace(' ', '-', \strtolower($name)); + + if ($name === $newName) { + continue; + } + + if (isset($packages[$newName])) { + $value .= '||' . $packages[$newName]; + } + + $packages[$newName] = $value; + unset($packages[$name]); + } + + return $packages; + } } diff --git a/test/Template/Vendor/Composer/ComposerJsonNormalizer/NormalizeNormalizesJson/Json/IsObject/HasEntries/Yes/HasProperty/ValueContainsPackagesAndVersionConstraints/HasEntries/Yes/HasNormalizedVersionConstraints/No/Extension/normalized.json b/test/Template/Vendor/Composer/ComposerJsonNormalizer/NormalizeNormalizesJson/Json/IsObject/HasEntries/Yes/HasProperty/ValueContainsPackagesAndVersionConstraints/HasEntries/Yes/HasNormalizedVersionConstraints/No/Extension/normalized.json new file mode 100644 index 00000000..81bee8c6 --- /dev/null +++ b/test/Template/Vendor/Composer/ComposerJsonNormalizer/NormalizeNormalizesJson/Json/IsObject/HasEntries/Yes/HasProperty/ValueContainsPackagesAndVersionConstraints/HasEntries/Yes/HasNormalizedVersionConstraints/No/Extension/normalized.json @@ -0,0 +1,6 @@ +{ + "homepage": "https://github.com/ergebnis/composer-normalize/issues/1388", + "value-contains-packages-and-version-constraints": { + "ext-extension-name": "1 || 2 || 3 || 4 || 5 || 6" + } +} diff --git a/test/Template/Vendor/Composer/ComposerJsonNormalizer/NormalizeNormalizesJson/Json/IsObject/HasEntries/Yes/HasProperty/ValueContainsPackagesAndVersionConstraints/HasEntries/Yes/HasNormalizedVersionConstraints/No/Extension/original.json b/test/Template/Vendor/Composer/ComposerJsonNormalizer/NormalizeNormalizesJson/Json/IsObject/HasEntries/Yes/HasProperty/ValueContainsPackagesAndVersionConstraints/HasEntries/Yes/HasNormalizedVersionConstraints/No/Extension/original.json new file mode 100644 index 00000000..ab3f2dfb --- /dev/null +++ b/test/Template/Vendor/Composer/ComposerJsonNormalizer/NormalizeNormalizesJson/Json/IsObject/HasEntries/Yes/HasProperty/ValueContainsPackagesAndVersionConstraints/HasEntries/Yes/HasNormalizedVersionConstraints/No/Extension/original.json @@ -0,0 +1,11 @@ +{ + "homepage": "https://github.com/ergebnis/composer-normalize/issues/1388", + "value-contains-packages-and-version-constraints": { + "ext-extension name": "1", + "ext-Extension Name": "2", + "ext-EXTENSION NAME": "3", + "ext-extension-name": "4", + "ext-Extension-Name": "5", + "ext-EXTENSION-NAME": "6" + } +}