QuestyCaptcha: trim trailing spaces from the user-submitted CAPTCHA answer

Bug: T368112
Change-Id: Id9257cb3319096852710ef2102ea9b596acf194b
This commit is contained in:
Jack Phoenix 2024-06-23 11:17:23 +03:00
parent 6b9452191f
commit b17f585275

View file

@ -24,16 +24,19 @@ class QuestyCaptcha extends SimpleCaptcha {
protected static $messagePrefix = 'questycaptcha-'; protected static $messagePrefix = 'questycaptcha-';
/** /**
* Validate a captcha response * Validate a CAPTCHA response
*
* @note Trimming done as per T368112
*
* @param string $answer * @param string $answer
* @param array $info * @param array $info
* @return bool * @return bool
*/ */
protected function keyMatch( $answer, $info ) { protected function keyMatch( $answer, $info ) {
if ( is_array( $info['answer'] ) ) { if ( is_array( $info['answer'] ) ) {
return in_array( strtolower( $answer ), array_map( 'strtolower', $info['answer'] ) ); return in_array( strtolower( trim( $answer ) ), array_map( 'strtolower', $info['answer'] ) );
} else { } else {
return strtolower( $answer ) == strtolower( $info['answer'] ); return strtolower( trim( $answer ) ) == strtolower( $info['answer'] );
} }
} }