Skip to content

Commit

Permalink
Fixed bug #10754: wrong validation of strings containing numbers by '…
Browse files Browse the repository at this point in the history
…compare' rule

git-svn-id: http://svn.php.net/repository/pear/packages/HTML_QuickForm/trunk@236912 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information
sad-spirit committed Jun 3, 2007
1 parent 678963e commit 374eeeb
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions QuickForm/Rule/Compare.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ class HTML_QuickForm_Rule_Compare extends HTML_QuickForm_Rule
* @access private
*/
var $_operators = array(
'eq' => '==',
'neq' => '!=',
'eq' => '===',
'neq' => '!==',
'gt' => '>',
'gte' => '>=',
'lt' => '<',
Expand All @@ -65,24 +65,24 @@ class HTML_QuickForm_Rule_Compare extends HTML_QuickForm_Rule
function _findOperator($name)
{
if (empty($name)) {
return '==';
return '===';
} elseif (isset($this->_operators[$name])) {
return $this->_operators[$name];
} elseif (in_array($name, $this->_operators)) {
return $name;
} else {
return '==';
return '===';
}
}


function validate($values, $operator = null)
{
$operator = $this->_findOperator($operator);
if ('==' != $operator && '!=' != $operator) {
if ('===' != $operator && '!==' != $operator) {
$compareFn = create_function('$a, $b', 'return floatval($a) ' . $operator . ' floatval($b);');
} else {
$compareFn = create_function('$a, $b', 'return $a ' . $operator . ' $b;');
$compareFn = create_function('$a, $b', 'return strval($a) ' . $operator . ' strval($b);');
}

return $compareFn($values[0], $values[1]);
Expand All @@ -92,10 +92,10 @@ function validate($values, $operator = null)
function getValidationScript($operator = null)
{
$operator = $this->_findOperator($operator);
if ('==' != $operator && '!=' != $operator) {
if ('===' != $operator && '!==' != $operator) {
$check = "!(Number({jsVar}[0]) {$operator} Number({jsVar}[1]))";
} else {
$check = "!({jsVar}[0] {$operator} {jsVar}[1])";
$check = "!(String({jsVar}[0]) {$operator} String({jsVar}[1]))";
}
return array('', "'' != {jsVar}[0] && {$check}");
}
Expand Down

0 comments on commit 374eeeb

Please sign in to comment.