Browse Source

Prevent require command from allowing a package to require itself, fixes #8247

Jordi Boggiano 5 năm trước cách đây
mục cha
commit
1a391b572c
1 tập tin đã thay đổi với 6 bổ sung1 xóa
  1. 6 1
      src/Composer/Command/RequireCommand.php

+ 6 - 1
src/Composer/Command/RequireCommand.php

@@ -145,7 +145,12 @@ EOT
 
         // validate requirements format
         $versionParser = new VersionParser();
-        foreach ($requirements as $constraint) {
+        foreach ($requirements as $package => $constraint) {
+            if (strtolower($package) === $composer->getPackage()->getName()) {
+                $io->writeError(sprintf('<error>Root package \'%s\' cannot require itself in its composer.json</error>', $package));
+
+                return 1;
+            }
             $versionParser->parseConstraints($constraint);
         }