From 9007a7fe5857db94ef7154a614bfa073d89f4d4d Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 16 Apr 2017 09:57:36 -0400 Subject: [PATCH] Fix notBlank() to pass on -0.0 Copy the implementation from 3.x as it works with -0.0 already. Refs #10521 --- lib/Cake/Test/Case/Utility/ValidationTest.php | 4 ++++ lib/Cake/Utility/Validation.php | 11 +++-------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/Cake/Test/Case/Utility/ValidationTest.php b/lib/Cake/Test/Case/Utility/ValidationTest.php index bec844dcb..1cb2bfd08 100644 --- a/lib/Cake/Test/Case/Utility/ValidationTest.php +++ b/lib/Cake/Test/Case/Utility/ValidationTest.php @@ -148,6 +148,10 @@ class ValidationTest extends CakeTestCase { * @return void */ public function testNotBlank() { + $this->assertTrue(Validation::notBlank(0)); + $this->assertTrue(Validation::notBlank(0.0)); + $this->assertTrue(Validation::notBlank(-0)); + $this->assertTrue(Validation::notBlank(-0.0)); $this->assertTrue(Validation::notBlank('abcdefg')); $this->assertTrue(Validation::notBlank('fasdf ')); $this->assertTrue(Validation::notBlank('fooo' . chr(243) . 'blabla')); diff --git a/lib/Cake/Utility/Validation.php b/lib/Cake/Utility/Validation.php index da614de1d..bc7a18829 100644 --- a/lib/Cake/Utility/Validation.php +++ b/lib/Cake/Utility/Validation.php @@ -66,19 +66,14 @@ class Validation { * * Returns true if string contains something other than whitespace * - * $check can be passed as an array: - * array('check' => 'valueToCheck'); - * - * @param string|array $check Value to check + * @param string $check Value to check * @return bool Success */ public static function notBlank($check) { - if (!is_scalar($check)) { - return false; - } - if (empty($check) && (string)$check !== '0') { + if (empty($check) && !is_bool($check) && !is_numeric($check)) { return false; } + return static::_check($check, '/[^\s]+/m'); }