1
0
Fork 0

Improve validating array loader to avoid false positives

pull/1288/head
Jordi Boggiano 2012-11-05 14:14:55 +01:00
parent e7e04689f1
commit e05391dc44
3 changed files with 9 additions and 5 deletions

View File

@ -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": {

View File

@ -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;
}

View File

@ -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',