Skip to content
Permalink
Browse files

[multisite:new] Validated uri name (#4039)

  • Loading branch information...
harold20 authored and enzolutions committed May 16, 2019
1 parent a122272 commit 039a0644192c516d6df15a213255402a2c04c802
Showing with 26 additions and 3 deletions.
  1. +10 −2 src/Command/Multisite/NewCommand.php
  2. +15 −0 src/Utils/Validator.php
  3. +1 −1 uninstall.services.yml
@@ -8,6 +8,7 @@
namespace Drupal\Console\Command\Multisite;
use Drupal\Console\Core\Command\Command;
use Drupal\Console\Utils\Validator;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
@@ -25,14 +26,21 @@ class NewCommand extends Command
{
protected $appRoot;
/**
* @var Validator
*/
protected $validator;
/**
* DebugCommand constructor.
*
* @param $appRoot
* @param Validator $validator
*/
public function __construct($appRoot)
public function __construct($appRoot, Validator $validator)
{
$this->appRoot = $appRoot;
$this->validator = $validator;
parent::__construct();
}
@@ -80,6 +88,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
{
$this->fs = new Filesystem();
$this->directory = $input->getArgument('directory');
$uri = $this->validator->validateUriName($input->getArgument('uri'));
if (!$this->directory) {
$this->getIo()->error($this->trans('commands.multisite.new.errors.subdir-empty'));
@@ -117,7 +126,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
return 1;
}
$uri = $input->getArgument('uri');
try {
$this->addToSitesFile($uri);
} catch (\Exception $e) {
@@ -17,6 +17,7 @@ class Validator
const REGEX_CONTROLLER_CLASS_NAME = '/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]+Controller$/';
const REGEX_MACHINE_NAME = '/^[a-z0-9_]+$/';
const REGEX_DEPENDENCY_NAME = '/^[a-z0-9_:]+$/';
const REGEX_URI_NAME = '/^[a-z0-9_.]+$/';
// This REGEX remove spaces between words
const REGEX_REMOVE_SPACES = '/[\\s+]/';
// Max length to 32
@@ -66,6 +67,20 @@ public function validateClassName($class_name)
}
}
public function validateUriName($uri_name)
{
if (preg_match(self::REGEX_URI_NAME, $uri_name)) {
return $uri_name;
} else {
throw new \InvalidArgumentException(
sprintf(
'Uri name "%s" is invalid, it must starts with a letter, followed by any number of letters, numbers, or underscores.',
$uri_name
)
);
}
}
public function validateBundleTitle($bundle_title)
{
if (!empty($bundle_title)) {
@@ -36,7 +36,7 @@ services:
- { name: drupal.command }
console.multisite_new:
class: Drupal\Console\Command\Multisite\NewCommand
arguments: ['@app.root']
arguments: ['@app.root', '@console.validator']
tags:
- { name: drupal.command }
console.multisite_update:

0 comments on commit 039a064

Please sign in to comment.
You can’t perform that action at this time.