From e05391dc4438d951cfb0d420bc985ce514434f92 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Mon, 5 Nov 2012 14:14:55 +0100 Subject: [PATCH] Improve validating array loader to avoid false positives --- res/composer-schema.json | 2 +- src/Composer/Package/Loader/ValidatingArrayLoader.php | 6 +++--- .../Test/Package/Loader/ValidatingArrayLoaderTest.php | 6 +++++- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/res/composer-schema.json b/res/composer-schema.json index 23c70c88e..b307264cf 100644 --- a/res/composer-schema.json +++ b/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": { diff --git a/src/Composer/Package/Loader/ValidatingArrayLoader.php b/src/Composer/Package/Loader/ValidatingArrayLoader.php index d7f6bda34..53e1cd07d 100644 --- a/src/Composer/Package/Loader/ValidatingArrayLoader.php +++ b/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; } diff --git a/tests/Composer/Test/Package/Loader/ValidatingArrayLoaderTest.php b/tests/Composer/Test/Package/Loader/ValidatingArrayLoaderTest.php index 84ec6d53f..1fab51f0c 100644 --- a/tests/Composer/Test/Package/Loader/ValidatingArrayLoaderTest.php +++ b/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',