mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Merge pull request #3880 from markstory/incorrect-validation
Fix issues with Validation::inList() and SecurityComponent
This commit is contained in:
commit
396725dc8c
3 changed files with 9 additions and 6 deletions
|
@ -470,8 +470,8 @@ class SecurityComponent extends Component {
|
|||
$multi = array();
|
||||
|
||||
foreach ($fieldList as $i => $key) {
|
||||
if (preg_match('/(\.\d+)+$/', $key)) {
|
||||
$multi[$i] = preg_replace('/(\.\d+)+$/', '', $key);
|
||||
if (preg_match('/(\.\d{1,10})+$/', $key)) {
|
||||
$multi[$i] = preg_replace('/(\.\d{1,10})+$/', '', $key);
|
||||
unset($fieldList[$i]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1979,6 +1979,10 @@ class ValidationTest extends CakeTestCase {
|
|||
$this->assertFalse(Validation::inList(2, array('1', '2x', '3')));
|
||||
$this->assertFalse(Validation::inList('One', array('one', 'two')));
|
||||
|
||||
// No hexadecimal for numbers.
|
||||
$this->assertFalse(Validation::inList('0x7B', array('ABC', '123')));
|
||||
$this->assertFalse(Validation::inList('0x7B', array('ABC', 123)));
|
||||
|
||||
// case insensitive
|
||||
$this->assertTrue(Validation::inList('one', array('One', 'Two'), true));
|
||||
$this->assertTrue(Validation::inList('Two', array('one', 'two'), true));
|
||||
|
|
|
@ -800,14 +800,13 @@ class Validation {
|
|||
* @return bool Success.
|
||||
*/
|
||||
public static function inList($check, $list, $caseInsensitive = false) {
|
||||
$strict = !is_numeric($check);
|
||||
|
||||
if ($caseInsensitive) {
|
||||
$list = array_map('mb_strtolower', $list);
|
||||
$check = mb_strtolower($check);
|
||||
} else {
|
||||
$list = array_map('strval', $list);
|
||||
}
|
||||
|
||||
return in_array((string)$check, $list, $strict);
|
||||
return in_array((string)$check, $list, true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue