From 843f367540e2c233cfcb59870c7ae7ef396a6e0a Mon Sep 17 00:00:00 2001 From: waldermort Date: Tue, 13 Jan 2015 20:10:53 +0800 Subject: [PATCH] Fix: Bypass code incorrectly compared When the bypass code is given the value of '0', PHP equates it to boolean false causing the validation to fail. --- Validator/CaptchaValidator.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Validator/CaptchaValidator.php b/Validator/CaptchaValidator.php index 4469cec..b3466bb 100644 --- a/Validator/CaptchaValidator.php +++ b/Validator/CaptchaValidator.php @@ -82,7 +82,7 @@ class CaptchaValidator } } - if (!($code && is_string($code) && ($this->compare($code, $expectedCode) || $this->compare($code, $this->bypassCode)))) { + if (!($code !== null && is_string($code) && ($this->compare($code, $expectedCode) || $this->compare($code, $this->bypassCode)))) { $form->addError(new FormError($this->translator->trans($this->invalidMessage, array(), 'validators'))); } else { if ($this->humanity > 0) { @@ -159,6 +159,6 @@ class CaptchaValidator */ protected function compare($code, $expectedCode) { - return ($expectedCode && is_string($expectedCode) && $this->niceize($code) == $this->niceize($expectedCode)); + return ($expectedCode !== null && is_string($expectedCode) && $this->niceize($code) == $this->niceize($expectedCode)); } }