Эх сурвалжийг харах

Improve validating array loader to avoid false positives

Jordi Boggiano 12 жил өмнө
parent
commit
e05391dc44

+ 1 - 1
res/composer-schema.json

@@ -9,7 +9,7 @@
             "required": true
         },
         "type": {
-            "description": "Package type, either 'library' for common packages, 'composer-installer' for custom installers, 'metapackage' for empty packages, or a custom type defined by whatever project this package applies to.",
+            "description": "Package type, either 'library' for common packages, 'composer-installer' for custom installers, 'metapackage' for empty packages, or a custom type ([a-z0-9-]+) defined by whatever project this package applies to.",
             "type": "string"
         },
         "target-dir": {

+ 3 - 3
src/Composer/Package/Loader/ValidatingArrayLoader.php

@@ -50,14 +50,14 @@ class ValidatingArrayLoader implements LoaderInterface
             }
         }
 
-        $this->validateRegex('type', '[a-z0-9-]+');
+        $this->validateRegex('type', '[A-Za-z0-9-]+');
         $this->validateString('target-dir');
         $this->validateArray('extra');
         $this->validateFlatArray('bin');
         $this->validateArray('scripts'); // TODO validate event names & listener syntax
         $this->validateString('description');
         $this->validateUrl('homepage');
-        $this->validateFlatArray('keywords', '[A-Za-z0-9 -]+');
+        $this->validateFlatArray('keywords', '[A-Za-z0-9 ._-]+');
 
         if (isset($this->config['license'])) {
             if (is_string($this->config['license'])) {
@@ -302,7 +302,7 @@ class ValidatingArrayLoader implements LoaderInterface
             }
 
             if ($regex && !preg_match('{^'.$regex.'$}u', $value)) {
-                $this->errors[] = $property.'.'.$key.' : invalid value, must match '.$regex;
+                $this->warnings[] = $property.'.'.$key.' : invalid value, must match '.$regex;
                 unset($this->config[$property][$key]);
                 $pass = false;
             }

+ 5 - 1
tests/Composer/Test/Package/Loader/ValidatingArrayLoaderTest.php

@@ -47,7 +47,7 @@ class ValidatingArrayLoaderTest extends \PHPUnit_Framework_TestCase
                     'description' => 'Foo bar',
                     'version' => '1.0.0',
                     'type' => 'library',
-                    'keywords' => array('a', 'b'),
+                    'keywords' => array('a', 'b_c', 'D E'),
                     'homepage' => 'https://foo.com',
                     'time' => '2010-10-10T10:10:10+00:00',
                     'license' => 'MIT',
@@ -131,6 +131,10 @@ class ValidatingArrayLoaderTest extends \PHPUnit_Framework_TestCase
                     ),
                     'extra' => array(
                         'random' => array('stuff' => array('deeply' => 'nested')),
+                        'branch-alias' => array(
+                            'dev-master' => '2.0-dev',
+                            'dev-old' => '1.0.x-dev',
+                        ),
                     ),
                     'bin' => array(
                         'bin/foo',