fixed do not validate uploaded file name

git-svn-id: http://xe-core.googlecode.com/svn/branches/1.5.0@9014 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
flyskyko 2011-09-03 12:01:56 +00:00
parent 455aeb4326
commit 8e20c6057e

View file

@ -26,7 +26,7 @@ class Validator
$this->_xml_ruleset = null;
if($xml_path) $this->load($xml_path);
// predefined rules
$this->addRule(array(
'email' => '/^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/',
@ -148,7 +148,7 @@ class Validator
'if' => array()
);
$fields = array_map('trim', $fields);
$fields = array_map(array($this, 'arrayTrim'), $fields);
$field_names = array_keys($fields);
$filters = $this->_filters;
@ -237,6 +237,21 @@ class Validator
return true;
}
/**
* apply trim recursive
*/
function arrayTrim($array)
{
if (!is_array($array)) return trim($array);
foreach($array as $key => $value)
{
$array[$key] = $this->arrayTrim($value);
}
return $array;
}
/**
* Log an error
* @param[in] $msg error message
@ -305,7 +320,7 @@ class Validator
unset($filter['if']);
}
}
$this->_filters[$name] = $filter;
}
}
@ -323,6 +338,11 @@ class Validator
function applyRule($name, $value){
$rule = $this->_rules[$name];
if (is_array($value) && isset($value['tmp_name']))
{
$value = $value['name'];
}
switch($rule['type']) {
case 'regex':
return (preg_match($rule['test'], $value) > 0);
@ -339,7 +359,7 @@ class Validator
}
/**
* Return
* Return
*/
function mbStrLen($str){
$arr = count_chars($str);