[-] Core: fix regular expression patterns for some hosting which don't support unicode

This commit is contained in:
rGaillard
2012-11-16 11:04:27 +00:00
parent 45b0fe885d
commit fc523f368e
2 changed files with 17 additions and 5 deletions
+12
View File
@@ -2247,6 +2247,18 @@ FileETag INode MTime Size
else
return array_unique($array, SORT_REGULAR);
}
/**
* Delete unicode class from regular expression patterns
* @param string $pattern
* @return pattern
*/
public static function cleanNonUnicodeSupport($pattern)
{
if (!defined('PREG_BAD_UTF8_OFFSET'))
return $pattern;
return preg_replace('/\\\[px]\{[a-z]\}{1,2}|(\/[a-z]*)u([a-z]*)$/i', "$1$2", $pattern);
}
}
/**
+5 -5
View File
@@ -45,7 +45,7 @@ class ValidateCore
*/
public static function isEmail($email)
{
return !empty($email) && preg_match('/^[a-z\p{L}0-9!#$%&\'*+\/=?^`{}|~_-]+[.a-z\p{L}0-9!#$%&\'*+\/=?^`{}|~_-]*@[a-z\p{L}0-9]+[._a-z\p{L}0-9-]*\.[a-z0-9]+$/ui', $email);
return !empty($email) && preg_match(Tools::cleanNonUnicodeSupport('/^[a-z\p{L}0-9!#$%&\'*+\/=?^`{}|~_-]+[.a-z\p{L}0-9!#$%&\'*+\/=?^`{}|~_-]*@[a-z\p{L}0-9]+[._a-z\p{L}0-9-]*\.[a-z0-9]+$/ui'), $email);
}
/**
@@ -131,7 +131,7 @@ class ValidateCore
*/
public static function isCarrierName($name)
{
return empty($name) || preg_match('/^[^<>;=#{}]*$/u', $name);
return empty($name) || preg_match(Tools::cleanNonUnicodeSupport('/^[^<>;=#{}]*$/u'), $name);
}
/**
@@ -153,7 +153,7 @@ class ValidateCore
*/
public static function isName($name)
{
return preg_match('/^[^0-9!<>,;?=+()@#"°{}_$%:]*$/u', stripslashes($name));
return preg_match(Tools::cleanNonUnicodeSupport('/^[^0-9!<>,;?=+()@#"°{}_$%:]*$/u'), stripslashes($name));
}
/**
@@ -175,7 +175,7 @@ class ValidateCore
*/
public static function isMailName($mail_name)
{
return preg_match('/^[^<>;=#{}]*$/u', $mail_name);
return preg_match(Tools::cleanNonUnicodeSupport('/^[^<>;=#{}]*$/u'), $mail_name);
}
/**
@@ -186,7 +186,7 @@ class ValidateCore
*/
public static function isMailSubject($mail_subject)
{
return preg_match('/^[^<>]*$/u', $mail_subject);
return preg_match(Tools::cleanNonUnicodeSupport('/^[^<>]*$/u'), $mail_subject);
}
/**