Permalink
Browse files

Merge pull request #737 from jails/pr1

Fix #427
  • Loading branch information...
2 parents d838b9d + 0180092 commit 62b8b7abe3e44ee58a33d82c410df25ec13bc82d @nateabele nateabele committed Dec 14, 2012
Showing with 24 additions and 1 deletion.
  1. +22 −0 tests/cases/util/ValidatorTest.php
  2. +2 −1 util/Validator.php
View
22 tests/cases/util/ValidatorTest.php
@@ -414,6 +414,28 @@ function testInList() {
$this->assertTrue(Validator::isInList('one', null, array('list' => array('one', 'two'))));
$this->assertTrue(Validator::isInList('two', null, array('list' => array('one', 'two'))));
$this->assertFalse(Validator::isInList('3', null, array('list' => array('one', 'two'))));
+
+ $this->assertFalse(Validator::isInList('', null, array('list' => array('0', '1'))));
+ $this->assertFalse(Validator::isInList(null, null, array('list' => array('0', '1'))));
+ $this->assertFalse(Validator::isInList(false, null, array('list' => array('0', '1'))));
+ $this->assertFalse(Validator::isInList(true, null, array('list' => array('0', '1'))));
+
+ $this->assertFalse(Validator::isInList('', null, array('list' => array(0, 1))));
+ $this->assertFalse(Validator::isInList(null, null, array('list' => array(0, 1))));
+ $this->assertFalse(Validator::isInList(false, null, array('list' => array(0, 1))));
+ $this->assertFalse(Validator::isInList(true, null, array('list' => array(0, 1))));
+ $this->assertTrue(Validator::isInList(0, null, array('list' => array(0, 1))));
+ $this->assertTrue(Validator::isInList(1, null, array('list' => array(0, 1))));
+ $this->assertFalse(Validator::isInList(2, null, array('list' => array(0, 1))));
+
+ $this->assertTrue(Validator::isInList(0, null, array('list' => array('0', '1'))));
+ $this->assertTrue(Validator::isInList('1', null, array('list' => array('0', '1'))));
+
+ $this->assertTrue(Validator::isInList(1, null, array('list' => array('0', '1'))));
+ $this->assertTrue(Validator::isInList('1', null, array('list' => array('0', '1'))));
+
+ $this->assertFalse(Validator::isInList(2, null, array('list' => array('0', '1'))));
+ $this->assertFalse(Validator::isInList('2', null, array('list' => array('0', '1'))));
}
View
3 util/Validator.php
@@ -273,7 +273,8 @@ public static function __init() {
},
'inList' => function($value, $format, $options) {
$options += array('list' => array());
- return in_array($value, $options['list']);
+ $strict = is_bool($value) || $value === '';
+ return in_array($value, $options['list'], $strict);
},
'lengthBetween' => function($value, $format, $options) {
$length = strlen($value);

0 comments on commit 62b8b7a

Please sign in to comment.