mirror of
https://github.com/yiisoft/yii.git
synced 2026-02-19 17:11:23 +01:00
Fix deprecation in CCaptchaAction for PHP 8.1+
This commit is contained in:
@@ -5,6 +5,7 @@ Version 1.1.32 under development
|
||||
--------------------------------
|
||||
|
||||
- Enh #4587: Add socket connection support to `CRedisCache` (mateusmetzker)
|
||||
- Bug #4591: Fix deprecation in `CCaptchaAction` for PHP 8.1+ (rob006)
|
||||
|
||||
Version 1.1.31 April 10, 2025
|
||||
--------------------------------
|
||||
|
||||
@@ -47,8 +47,7 @@ class CCaptchaValidator extends CValidator
|
||||
if($this->allowEmpty && $this->isEmpty($value))
|
||||
return;
|
||||
$captcha=$this->getCaptchaAction();
|
||||
// reason of array checking is explained here: https://github.com/yiisoft/yii/issues/1955
|
||||
if(is_array($value) || !$captcha->validate($value,$this->caseSensitive))
|
||||
if(!$captcha->validate($value,$this->caseSensitive))
|
||||
{
|
||||
$message=$this->message!==null?$this->message:Yii::t('yii','The verification code is incorrect.');
|
||||
$this->addError($object,$attribute,$message);
|
||||
@@ -121,4 +120,3 @@ if(jQuery.trim(value)!='') {
|
||||
return $js;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -173,6 +173,8 @@ class CCaptchaAction extends CAction
|
||||
*/
|
||||
public function validate($input,$caseSensitive)
|
||||
{
|
||||
if(!is_string($input))
|
||||
return false;
|
||||
$code = $this->getVerifyCode();
|
||||
$valid = $caseSensitive ? ($input === $code) : strcasecmp($input,$code)===0;
|
||||
$session = Yii::app()->session;
|
||||
|
||||
46
tests/framework/validators/CCaptchaValidatorTest.php
Normal file
46
tests/framework/validators/CCaptchaValidatorTest.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
require_once 'ModelMock.php';
|
||||
|
||||
/**
|
||||
* Class CCaptchaValidatorTest.
|
||||
*
|
||||
* @author Robert Korulczyk <robert@korulczyk.pl>
|
||||
*/
|
||||
class CCaptchaValidatorTest extends CTestCase
|
||||
{
|
||||
|
||||
public function testInvalidInput() {
|
||||
Yii::app()->setController(new CCaptchaValidatorTestController('CCaptchaValidatorTest'));
|
||||
|
||||
$rules = array(
|
||||
array('foo', 'captcha')
|
||||
);
|
||||
|
||||
$stub = $this->getMock('ModelMock', array('rules'));
|
||||
$stub->expects($this->any())
|
||||
->method('rules')
|
||||
->will($this->returnValue($rules));
|
||||
|
||||
$stub->foo = null;
|
||||
$this->assertFalse($stub->validate());
|
||||
|
||||
$stub->foo = array();
|
||||
$this->assertFalse($stub->validate());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Class CCaptchaValidatorTestController.
|
||||
*
|
||||
* @author Robert Korulczyk <robert@korulczyk.pl>
|
||||
*/
|
||||
class CCaptchaValidatorTestController extends CController
|
||||
{
|
||||
public function actions()
|
||||
{
|
||||
return array(
|
||||
'captcha' => 'CCaptchaAction',
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user