? 5-check.patch
Index: domain.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/domain/domain.module,v
retrieving revision 1.40.2.36
diff -u -p -r1.40.2.36 domain.module
--- domain.module	31 Oct 2009 19:47:58 -0000	1.40.2.36
+++ domain.module	2 Nov 2009 22:21:31 -0000
@@ -587,7 +587,7 @@ function domain_domainload(&$domain) {
 function domain_get_path($domain) {
   global $base_url;
   if (empty($base_url)) {
-    return check_url($domain['scheme'] .'://'. $domain['subdomain']);
+    return $domain['scheme'] .'://'. $domain['subdomain'];
   }
   $_url = parse_url($base_url);
   // PHP 5 does not return an empty path element.
@@ -598,7 +598,7 @@ function domain_get_path($domain) {
   if (substr($_url['path'], -1) != '/') {
     $_url['path'] .= '/';
   }
-  $path = check_url($domain['scheme'] .'://'. $domain['subdomain'] . $_url['path']);
+  $path = $domain['scheme'] .'://'. $domain['subdomain'] . $_url['path'];
   return $path;
 }
 
@@ -606,7 +606,7 @@ function domain_get_path($domain) {
  * Determine an absolute path to the current page
  */
 function domain_get_uri($domain) {
-  $path = check_url($domain['scheme'] .'://'. $domain['subdomain'] . request_uri());
+  $path = $domain['scheme'] .'://'. $domain['subdomain'] . request_uri();
   return $path;
 }
 
@@ -1496,3 +1496,79 @@ function domain_node_access_explain($row
   }
   return $return;
 }
+
+/**
+ * Validates a domain string.
+ * @param string $subdomain
+ *   The string to check for domain validity
+ * @return array
+ *   List of error messages or empty array.
+ */
+function domain_validate($subdomain) {
+  $error_list = array();
+  // Validate the domains format generically for now.
+  $error = domain_valid_domain($subdomain);
+  if (!empty($error)) {
+    $error_list[] = $error;
+  }
+  // Make sure domain is unique
+  if (!domain_unique_domain($subdomain)) {
+    $error_list[] = t('The domain value must be unique.');
+  }
+  return $error_list;
+}
+
+/**
+ * Validate the domain against all correctable errors.
+ *
+ * Note that we decided not to check for valid TLDs here.
+ *
+ * @param $subdomain
+ *   Domain string to check.
+ * @return string
+ *   Empty if valid, error message on invalid.
+ */
+function domain_valid_domain($subdomain) {
+  $error_list = array();
+  // Check for one colon only.
+  if (substr_count($subdomain, ':') > 1) {
+    $error_list[] = t('Only one colon (:) is allowed.');
+  }
+  // If a colon, make sure it is only followed by numbers.
+  else if (substr_count($subdomain, ':') == 1) {
+    $parts = explode(':', $subdomain);
+    $port = (int) $parts[1];
+    if (strcmp($port, $parts[1])) {
+      $error_list[] = t('The port protocol must be an integer.');
+    }
+  }
+  // The domain cannot begin or end with a period.
+  if (substr($subdomain, 0, 1) == '.') {
+    $error_list[] = t('The domain must not begin with a dot (.)');
+  }
+  // The domain cannot begin or end with a period.
+  if (substr($subdomain, -1) == '.') {
+    $error_list[] = t('The domain must not end with a dot (.)');
+  }
+  // Check for valid characters
+  $pattern = '/^[a-z0-9\.\-:]*$/i';
+  if (!preg_match($pattern, $subdomain)) {
+    $error_list[] = t('Only alphanumeric characters, dashes, and a colon are allowed.');
+  }
+  if (!empty($error_list)) {
+    return t('The domain string is invalid:') . theme('item_list', $error_list);
+  }
+}
+
+/**
+ * Validate the domain against existing domains.
+ *
+ * @param $subdomain
+ *   Domain string to check
+ * @return bool
+ *   TRUE if unique; FALSE if duplicate.
+ */
+function domain_unique_domain($subdomain) {
+  $count = db_result(db_query("SELECT COUNT(domain_id) FROM {domain} WHERE subdomain = '%s'", $subdomain));
+  return !(bool) $count;
+}
Index: domain_admin.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/domain/Attic/domain_admin.inc,v
retrieving revision 1.29.2.16
diff -u -p -r1.29.2.16 domain_admin.inc
--- domain_admin.inc	31 Oct 2009 19:38:55 -0000	1.29.2.16
+++ domain_admin.inc	2 Nov 2009 22:21:32 -0000
@@ -476,15 +476,10 @@ function domain_create_form($arguments =
  */
 function domain_create_form_validate($form_id, $form_values) {
   // TODO: Make this a proper regex?
-  $subdomain = strtolower(urlencode($form_values['subdomain']));
-  $check = db_result(db_query("SELECT COUNT(domain_id) FROM {domain} WHERE subdomain = '%s'", $subdomain));
-  if ($check) {
-    form_set_error('subdomain', t('The subdomain value must be unique.'));
-  }
-  $check = NULL;
-  $check = db_result(db_query("SELECT COUNT(domain_id) FROM {domain} WHERE sitename = '%s'", $form_values['sitename']));
-  if ($check) {
-    form_set_error('sitename', t('The site name value must be unique.'));
+  $subdomain = strtolower($form_values['subdomain']);
+  $error_list = domain_validate($subdomain);
+  foreach ($error_list as $error) {
+    form_set_error('subdomain', $error);
   }
 }
 
@@ -587,16 +582,15 @@ function domain_edit_form($domain, $argu
 /**
  * FormsAPI for domain_edit_form()
  */
-function domain_edit_form_validate($form_id, $form_values) {
+function domain_edit_form_validate($form_id, $form_values, $form) {
   // TODO: Make this a proper regex
-  $subdomain = strtolower(urlencode($form_values['subdomain']));
-  $check = db_result(db_query("SELECT COUNT(domain_id) FROM {domain} WHERE subdomain = '%s' AND domain_id <> %d", $subdomain, $form_values['domain_id']));
-  if ($check) {
-    form_set_error('subdomain', t('The subdomain value must be unique.'));
-  }
-  $check2 = db_result(db_query("SELECT COUNT(domain_id) FROM {domain} WHERE sitename = '%s' AND domain_id <> %d", $form_values['sitename'], $form_values['domain_id']));
-  if ($check2) {
-    form_set_error('sitename', t('The site name value must be unique.'));
+  $subdomain = strtolower($form_values['subdomain']);
+  $domain_changed = (bool) strcmp($form_values['subdomain'], $form['domain']['subdomain']['#default_value']);
+  if ($domain_changed) {
+    $error_list = domain_validate($subdomain);
+    foreach ($error_list as $error) {
+      form_set_error('subdomain', $error);
+    }
   }
 }
 
