Skip to content

Commit

Permalink
Make Validation class more strict when checking values in list.
Browse files Browse the repository at this point in the history
Use in_array() with 'strict' param. Affected rules are Validation::inList() and Validation::multiple().
  • Loading branch information
majna committed Mar 7, 2012
1 parent 17eb0e4 commit 4543a4c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 2 additions & 0 deletions lib/Cake/Test/Case/Utility/ValidationTest.php
Expand Up @@ -1806,6 +1806,7 @@ public function testInList() {
$this->assertTrue(Validation::inList('one', array('one', 'two')));
$this->assertTrue(Validation::inList('two', array('one', 'two')));
$this->assertFalse(Validation::inList('three', array('one', 'two')));
$this->assertFalse(Validation::inList('one', '1one', array(0, 1, 2, 3)));
}

/**
Expand Down Expand Up @@ -1903,6 +1904,7 @@ public function testMultiple() {
$this->assertFalse(Validation::multiple(array(0, 15, 20, 5), array('in' => range(0, 10))));
$this->assertFalse(Validation::multiple(array(0, 5, 10, 11), array('in' => range(0, 10))));
$this->assertFalse(Validation::multiple(array('boo', 'foo', 'bar'), array('in' => array('foo', 'bar', 'baz'))));
$this->assertFalse(Validation::multiple(array('foo', '1bar'), array('in' => range(0, 10))));

$this->assertTrue(Validation::multiple(array(0, 5, 10, 11), array('max' => 3)));
$this->assertFalse(Validation::multiple(array(0, 5, 10, 11, 55), array('max' => 3)));
Expand Down
4 changes: 2 additions & 2 deletions lib/Cake/Utility/Validation.php
Expand Up @@ -544,7 +544,7 @@ public static function multiple($check, $options = array()) {
}
if ($options['in'] && is_array($options['in'])) {
foreach ($check as $val) {
if (!in_array($val, $options['in'])) {
if (!in_array($val, $options['in'], true)) {
return false;
}
}
Expand Down Expand Up @@ -719,7 +719,7 @@ public static function url($check, $strict = false) {
* @return boolean Success
*/
public static function inList($check, $list) {
return in_array($check, $list);
return in_array($check, $list, true);
}

/**
Expand Down

0 comments on commit 4543a4c

Please sign in to comment.