From da5ee6e2d742d4b7f9d39134f2b5b176c070ed1c Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Thu, 22 Nov 2012 19:50:27 +0100 Subject: [PATCH] Add warning for invalid chars in package names --- src/Composer/DependencyResolver/Problem.php | 6 ++++++ src/Composer/Package/Loader/ValidatingArrayLoader.php | 3 +++ 2 files changed, 9 insertions(+) diff --git a/src/Composer/DependencyResolver/Problem.php b/src/Composer/DependencyResolver/Problem.php index e199110ee..560fbb5dd 100644 --- a/src/Composer/DependencyResolver/Problem.php +++ b/src/Composer/DependencyResolver/Problem.php @@ -95,6 +95,12 @@ class Problem return "\n - The requested linked library ".$job['packageName'].$this->constraintToText($job['constraint']).' has the wrong version installed or is missing from your system, make sure to have the extension providing it.'; } + if (!preg_match('{^[A-Za-z0-9_./-]+$}', $job['packageName'])) { + $illegalChars = preg_replace('{[A-Za-z0-9_./-]+}', '', $job['packageName']); + + return "\n - The requested package ".$job['packageName'].' could not be found, it looks like its name is invalid, "'.$illegalChars.'" is not allowed in package names.'; + } + if (!$this->pool->whatProvides($job['packageName'])) { return "\n - The requested package ".$job['packageName'].' could not be found in any version, there may be a typo in the package name.'; } diff --git a/src/Composer/Package/Loader/ValidatingArrayLoader.php b/src/Composer/Package/Loader/ValidatingArrayLoader.php index 25d1109a4..87ce0036d 100644 --- a/src/Composer/Package/Loader/ValidatingArrayLoader.php +++ b/src/Composer/Package/Loader/ValidatingArrayLoader.php @@ -145,6 +145,9 @@ class ValidatingArrayLoader implements LoaderInterface foreach (array_keys(BasePackage::$supportedLinkTypes) as $linkType) { if ($this->validateArray($linkType) && isset($this->config[$linkType])) { foreach ($this->config[$linkType] as $package => $constraint) { + if (!preg_match('{^[A-Za-z0-9_./-]+$}', $package)) { + $this->warnings[] = $linkType.'.'.$package.' : invalid key, package names must be strings containing only [A-Za-z0-9_./-]'; + } if (!is_string($constraint)) { $this->errors[] = $linkType.'.'.$package.' : invalid value, must be a string containing a version constraint'; unset($this->config[$linkType][$package]);