From 9a656854adf77fb984bb806986d493bba7f673fd Mon Sep 17 00:00:00 2001 From: Stephan Date: Tue, 6 Feb 2024 16:18:41 +0000 Subject: [PATCH] ValidatingArrayLoader: fix link validation with missing name (#11830) --- src/Composer/Package/Loader/ValidatingArrayLoader.php | 2 +- .../Test/Package/Loader/ValidatingArrayLoaderTest.php | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Composer/Package/Loader/ValidatingArrayLoader.php b/src/Composer/Package/Loader/ValidatingArrayLoader.php index 9f25ed219..a94448a61 100644 --- a/src/Composer/Package/Loader/ValidatingArrayLoader.php +++ b/src/Composer/Package/Loader/ValidatingArrayLoader.php @@ -253,7 +253,7 @@ class ValidatingArrayLoader implements LoaderInterface if ($this->validateArray($linkType) && isset($this->config[$linkType])) { foreach ($this->config[$linkType] as $package => $constraint) { $package = (string) $package; - if (0 === strcasecmp($package, $this->config['name'])) { + if (isset($this->config['name']) && 0 === strcasecmp($package, $this->config['name'])) { $this->errors[] = $linkType.'.'.$package.' : a package cannot set a '.$linkType.' on itself'; unset($this->config[$linkType][$package]); continue; diff --git a/tests/Composer/Test/Package/Loader/ValidatingArrayLoaderTest.php b/tests/Composer/Test/Package/Loader/ValidatingArrayLoaderTest.php index bcd029733..40f05894e 100644 --- a/tests/Composer/Test/Package/Loader/ValidatingArrayLoaderTest.php +++ b/tests/Composer/Test/Package/Loader/ValidatingArrayLoaderTest.php @@ -426,6 +426,12 @@ class ValidatingArrayLoaderTest extends TestCase ], ['replace.0 : invalid version constraint (Could not parse version constraint acme/bar: Invalid version string "acme/bar")'], ], + [ + [ + 'require' => ['acme/bar' => '^1.0'] + ], + ['name : must be present'], + ] ]); }