Browse Source

Make sure newlines at the end of a package name are forbidden

Jordi Boggiano 6 years ago
parent
commit
ab3272e7a8
1 changed files with 2 additions and 2 deletions
  1. 2 2
      src/Packagist/WebBundle/Entity/Package.php

+ 2 - 2
src/Packagist/WebBundle/Entity/Package.php

@@ -280,7 +280,7 @@ class Package
                 return;
             }
 
-            if (!preg_match('{^[a-z0-9]([_.-]?[a-z0-9]+)*/[a-z0-9]([_.-]?[a-z0-9]+)*$}i', $information['name'])) {
+            if (!preg_match('{^[a-z0-9]([_.-]?[a-z0-9]+)*/[a-z0-9]([_.-]?[a-z0-9]+)*$}iD', $information['name'])) {
                 $context->buildViolation('The package name '.htmlentities($information['name'], ENT_COMPAT, 'utf-8').' is invalid, it should have a vendor name, a forward slash, and a package name. The vendor and package name can be words separated by -, . or _. The complete name should match "[a-z0-9]([_.-]?[a-z0-9]+)*/[a-z0-9]([_.-]?[a-z0-9]+)*".')
                     ->atPath($property)
                     ->addViolation()
@@ -625,7 +625,7 @@ class Package
                 return;
             }
             if (null === $this->getName()) {
-                $this->setName($information['name']);
+                $this->setName(trim($information['name']));
             }
             if ($driver instanceof GitHubDriver) {
                 $this->repository = $driver->getRepositoryUrl();