Skip to content

Commit

Permalink
Merge pull request #8701 from cakephp/dereuromark-patch-1
Browse files Browse the repository at this point in the history
notBlank rule should not false positive on numeric input
  • Loading branch information
markstory committed Apr 26, 2016
2 parents cd1d635 + bf570b4 commit 21012cc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/Validation/Validation.php
Expand Up @@ -83,7 +83,7 @@ public static function notEmpty($check)
*/
public static function notBlank($check)
{
if (empty($check) && $check !== '0') {
if (empty($check) && $check !== '0' && $check !== 0) {
return false;
}
return static::_check($check, '/[^\s]+/m');
Expand Down Expand Up @@ -481,7 +481,8 @@ public static function localizedTime($check, $type = 'datetime', $format = null)
if (empty($methods[$type])) {
throw new \InvalidArgumentException('Unsupported parser type given.');
}
return (Time::{$methods[$type]}($check, $format) !== null);
$method = $methods[$type];
return (Time::$method($check, $format) !== null);
}

/**
Expand Down
18 changes: 15 additions & 3 deletions tests/TestCase/Validation/ValidationTest.php
Expand Up @@ -30,6 +30,16 @@
class ValidationTest extends TestCase
{

/**
* @var string
*/
public $locale;

/**
* @var string
*/
protected $_appEncoding;

/**
* setUp method
*
Expand Down Expand Up @@ -60,7 +70,7 @@ public function tearDown()
*
* @return void
*/
public function testNotEmpty()
public function testNotBlank()
{
$this->assertTrue(Validation::notBlank('abcdefg'));
$this->assertTrue(Validation::notBlank('fasdf '));
Expand All @@ -69,6 +79,8 @@ public function testNotEmpty()
$this->assertTrue(Validation::notBlank('José'));
$this->assertTrue(Validation::notBlank('é'));
$this->assertTrue(Validation::notBlank('π'));
$this->assertTrue(Validation::notBlank('0'));
$this->assertTrue(Validation::notBlank(0));
$this->assertFalse(Validation::notBlank("\t "));
$this->assertFalse(Validation::notBlank(""));
}
Expand All @@ -78,7 +90,7 @@ public function testNotEmpty()
*
* @return void
*/
public function testNotEmptyISO88591AppEncoding()
public function testNotBlankIso88591AppEncoding()
{
Configure::write('App.encoding', 'ISO-8859-1');
$this->assertTrue(Validation::notBlank('abcdefg'));
Expand Down Expand Up @@ -1862,7 +1874,7 @@ public function testEmail()
*/
public function testEmailDeep()
{
$this->skipIf(gethostbynamel('example.abcd'), 'Your DNS service responds for non-existant domains, skipping deep email checks.');
$this->skipIf((bool)gethostbynamel('example.abcd'), 'Your DNS service responds for non-existant domains, skipping deep email checks.');

$this->assertTrue(Validation::email('abc.efg@cakephp.org', true));
$this->assertFalse(Validation::email('abc.efg@caphpkeinvalid.com', true));
Expand Down

0 comments on commit 21012cc

Please sign in to comment.