Skip to content
This repository has been archived by the owner on Sep 23, 2022. It is now read-only.

Commit

Permalink
Do not block adding a repo only if it's name does not validate a too …
Browse files Browse the repository at this point in the history
…restrictive regex rule
  • Loading branch information
wysow committed Apr 4, 2015
1 parent c72a384 commit 983c9a6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 24 deletions.
41 changes: 18 additions & 23 deletions src/Knp/Bundle/KnpBundlesBundle/Controller/BundleController.php
Expand Up @@ -307,35 +307,30 @@ public function addAction(Request $request)

if (!$error && ($request->isXmlHttpRequest() || 'POST' === $request->getMethod())) {
$bundle = trim(str_replace(array('http://github.com', 'https://github.com', '.git'), '', $bundle), '/');
if (preg_match('/^[a-z0-9-]+\/[a-z0-9-]+$/i', $bundle)) {
list($ownerName, $name) = explode('/', $bundle);
list($ownerName, $name) = explode('/', $bundle);

$url = $this->generateUrl('bundle_show', array('ownerName' => $ownerName, 'name' => $name));
if ($this->getRepository('Bundle')->findOneBy(array('ownerName' => $ownerName, 'name' => $name))) {
$url = $this->generateUrl('bundle_show', array('ownerName' => $ownerName, 'name' => $name));
if ($this->getRepository('Bundle')->findOneBy(array('ownerName' => $ownerName, 'name' => $name))) {
if (!$request->isXmlHttpRequest()) {
return $this->redirect($url);
}

$error = true;
$message = 'Specified bundle already <a href="'.$url.'">exists</a> at KnpBundles.com!';
}

if (!$error) {
/** @var $updater \Knp\Bundle\KnpBundlesBundle\Updater\Updater */
$updater = $this->get('knp_bundles.updater');
if ($updater->addBundle($bundle)) {
if (!$request->isXmlHttpRequest()) {
return $this->redirect($url);
}

$message = '<strong>Hey, friend!</strong> Thanks for adding <a href="'.$url.'">your bundle</a> to our database!';
} else {
$error = true;
$message = 'Specified bundle already <a href="'.$url.'">exists</a> at KnpBundles.com!';
$message = 'Specified repository is not valid Symfony2 bundle!';
}

if (!$error) {
/** @var $updater \Knp\Bundle\KnpBundlesBundle\Updater\Updater */
$updater = $this->get('knp_bundles.updater');
if ($updater->addBundle($bundle)) {
if (!$request->isXmlHttpRequest()) {
return $this->redirect($url);
}
$message = '<strong>Hey, friend!</strong> Thanks for adding <a href="'.$url.'">your bundle</a> to our database!';
} else {
$error = true;
$message = 'Specified repository is not valid Symfony2 bundle!';
}
}
} else {
$error = true;
$message = 'Please enter a valid GitHub repo name (e.g. KnpLabs/KnpBundles).';
}
}

Expand Down
Expand Up @@ -41,7 +41,7 @@ bundle_get_badge:
bundle_show:
pattern: /{ownerName}/{name}.{_format}
defaults: { _controller: KnpBundlesBundle:Bundle:show, _format: html }
requirements: { _method: "GET", _format: "(html|json)" }
requirements: { _method: "GET", _format: "(html|json)", name: "[^/]++" }

bundle_settings:
pattern: /bundle/settings/{id}
Expand Down

0 comments on commit 983c9a6

Please sign in to comment.