1
0
Fork 0

Merge pull request #1349 from colinfrei/strictPackageName

Enforce stricter package names
pull/1352/head
Jordi Boggiano 2012-11-21 07:00:13 -08:00
commit 118e137a91
1 changed files with 10 additions and 2 deletions

View File

@ -159,6 +159,8 @@ EOT
if (!$name = $input->getOption('name')) { if (!$name = $input->getOption('name')) {
$name = basename($cwd); $name = basename($cwd);
$name = preg_replace('{(?:([a-z])([A-Z])|([A-Z])([A-Z][a-z]))}', '\\1\\3-\\2\\4', $name);
$name = strtolower($name);
if (isset($git['github.user'])) { if (isset($git['github.user'])) {
$name = $git['github.user'] . '/' . $name; $name = $git['github.user'] . '/' . $name;
} elseif (!empty($_SERVER['USERNAME'])) { } elseif (!empty($_SERVER['USERNAME'])) {
@ -169,6 +171,12 @@ EOT
// package names must be in the format foo/bar // package names must be in the format foo/bar
$name = $name . '/' . $name; $name = $name . '/' . $name;
} }
} else {
if (!preg_match('{^[a-z0-9_.-]+/[a-z0-9_.-]+$}', $name)) {
throw new \InvalidArgumentException(
'The package name '.$name.' is invalid, it should be lowercase and have a vendor name, a forward slash, and a package name, matching: [a-z0-9_.-]+/[a-z0-9_.-]+'
);
}
} }
$name = $dialog->askAndValidate( $name = $dialog->askAndValidate(
@ -179,9 +187,9 @@ EOT
return $name; return $name;
} }
if (!preg_match('{^[a-z0-9_.-]+/[a-z0-9_.-]+$}i', $value)) { if (!preg_match('{^[a-z0-9_.-]+/[a-z0-9_.-]+$}', $value)) {
throw new \InvalidArgumentException( throw new \InvalidArgumentException(
'The package name '.$value.' is invalid, it should have a vendor name, a forward slash, and a package name, matching: [a-z0-9_.-]+/[a-z0-9_.-]+' 'The package name '.$value.' is invalid, it should be lowercase and have a vendor name, a forward slash, and a package name, matching: [a-z0-9_.-]+/[a-z0-9_.-]+'
); );
} }