From 6c4bdd14cde9e7852f048233529cd6dc730700cd Mon Sep 17 00:00:00 2001 From: Colin Frei Date: Tue, 20 Nov 2012 20:49:45 +0100 Subject: [PATCH 1/3] require $name to be lowercase --- src/Composer/Command/InitCommand.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Composer/Command/InitCommand.php b/src/Composer/Command/InitCommand.php index 4c5871034..52bda71bf 100644 --- a/src/Composer/Command/InitCommand.php +++ b/src/Composer/Command/InitCommand.php @@ -179,9 +179,9 @@ EOT 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( - '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_.-]+' ); } From b4cf3d06fd7c1e1678e1938037ef6ff479e26190 Mon Sep 17 00:00:00 2001 From: Colin Frei Date: Tue, 20 Nov 2012 20:53:19 +0100 Subject: [PATCH 2/3] Make sure suggested value conforms to allowed values Regex for replacement from https://github.com/composer/packagist/blob/master/src/Packagist/WebBundle/Entity/Package.php#L191 --- src/Composer/Command/InitCommand.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Composer/Command/InitCommand.php b/src/Composer/Command/InitCommand.php index 52bda71bf..36eb5d1f4 100644 --- a/src/Composer/Command/InitCommand.php +++ b/src/Composer/Command/InitCommand.php @@ -159,6 +159,8 @@ EOT if (!$name = $input->getOption('name')) { $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'])) { $name = $git['github.user'] . '/' . $name; } elseif (!empty($_SERVER['USERNAME'])) { From e4b8fe85a1dec690722177215800a0e7ba633812 Mon Sep 17 00:00:00 2001 From: Colin Frei Date: Tue, 20 Nov 2012 20:54:48 +0100 Subject: [PATCH 3/3] Check --name value if it's passed in, as that's not validated anywhere --- src/Composer/Command/InitCommand.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Composer/Command/InitCommand.php b/src/Composer/Command/InitCommand.php index 36eb5d1f4..f21be1937 100644 --- a/src/Composer/Command/InitCommand.php +++ b/src/Composer/Command/InitCommand.php @@ -171,6 +171,12 @@ EOT // package names must be in the format foo/bar $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(