Permalink
Browse files

FS#1680 - improve email address validation in config plugin

- setting_email and setting_richemail updated to use mail_isvalid() from inc/mail.php
- _pattern improved if any plugin extends either class for its own settings (this maybe
  over cautious. Its probably very unlikely that any plugin does this).

darcs-hash:20090426231346-f07c6-2af83d890ff4d92b14637ef6024d3fb68ba97efd.gz
  • Loading branch information...
Chris Smith
Chris Smith committed Apr 26, 2009
1 parent 672f99c commit 3a4bb9d5b60597f13681e43dff1a37b3a2966735
Showing with 29 additions and 2 deletions.
  1. +29 −2 lib/plugins/config/settings/config.class.php
@@ -528,8 +528,35 @@ function html(&$plugin, $echo=false) {
}
if (!class_exists('setting_email')) {
+
+ require_once(DOKU_INC.'inc/mail.php');
+ if (!defined('SETTING_EMAIL_PATTERN')) define('SETTING_EMAIL_PATTERN','<^'.PREG_PATTERN_VALID_EMAIL.'$>');
+
class setting_email extends setting_string {
- var $_pattern = '#^\s*(([a-z0-9\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)(,\s*([a-z0-9\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+))*)?\s*$#i';
+ var $_pattern = SETTING_EMAIL_PATTERN; // no longer required, retained for backward compatibility - FIXME, may not be necessary
+
+ /**
+ * update setting with user provided value $input
+ * if value fails error check, save it
+ *
+ * @return true if changed, false otherwise (incl. on error)
+ */
+ function update($input) {
+ if (is_null($input)) return false;
+ if ($this->is_protected()) return false;
+
+ $value = is_null($this->_local) ? $this->_default : $this->_local;
+ if ($value == $input) return false;
+
+ if (!mail_isvalid($input)) {
+ $this->_error = true;
+ $this->_input = $input;
+ return false;
+ }
+
+ $this->_local = $input;
+ return true;
+ }
}
}
@@ -563,7 +590,7 @@ function update($input) {
$addr = $test;
}
- if ($this->_pattern && !preg_match($this->_pattern,$addr)) {
+ if (!mail_isvalid($addr)) {
$this->_error = true;
$this->_input = $input;
return false;

0 comments on commit 3a4bb9d

Please sign in to comment.