-- CRM-16617, added function to check valid db name
authorPradeep Nayak <pradpnayak@gmail.com>
Tue, 25 Aug 2015 21:28:32 +0000 (02:58 +0530)
committerPradeep Nayak <pradpnayak@gmail.com>
Fri, 11 Sep 2015 18:53:05 +0000 (00:23 +0530)
----------------------------------------
* CRM-16617:
  https://issues.civicrm.org/jira/browse/CRM-16617

install/index.php

index 87a45d6d4ab49f18b0463d3a08129063eb5e8f1a..313c8f0eeeb764fdfbb12d4cdbd0d8712c43f1d9 100644 (file)
@@ -354,6 +354,14 @@ class InstallRequirements {
         );
       }
       $onlyRequire = ($dbName == 'Drupal') ? TRUE : FALSE;
+      $this->requireValidDBName(
+        $databaseConfig['database'],
+        array(     
+          ts("MySQL %1 Configuration", array(1 => $dbName)),
+          ts("Is the provided database name valid?"),
+          ts("The database name provided is not valid. Please use only 0-9, a-z, A-Z and _ as characters in the name."),
+        )
+      );
       $this->requireDatabaseOrCreatePermissions(
         $databaseConfig['server'],
         $databaseConfig['username'],
@@ -1210,6 +1218,25 @@ class InstallRequirements {
     return count($this->warnings);
   }
 
+  /**
+   * function to check valid db name
+   *
+   * @param $database
+   * @param $testDetails
+   */
+  public function requireValidDBName($database, $testDetails) {
+    $matches = array();
+    preg_match(
+      "/^[0-9]*[a-zA-Z_]+[a-zA-Z0-9_]*$/",
+      $database,
+      $matches
+    );
+    if (empty($matches)) {
+      $this->error($testDetails);
+      return;
+    }
+  }
+
 }
 
 /**