From e8ea6872f9ffda94f0ee2c12410a50b3dc1c6afd Mon Sep 17 00:00:00 2001 From: elachlan <elachlan@1021502.no-reply.drupal.org> Date: Wed, 15 Aug 2018 12:58:37 +1000 Subject: [PATCH] #2474959, #2992697 Fix for failing test --- captcha.module | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/captcha.module b/captcha.module index 010a95d..42366c9 100755 --- a/captcha.module +++ b/captcha.module @@ -421,11 +421,13 @@ function _captcha_get_posted_captcha_info(array $element, FormStateInterface $fo $posted_captcha_sid = NULL; } - // Invalidate CAPTCHA token to avoid reuse. - \Drupal::database()->update('captcha_sessions') - ->fields(['token' => NULL]) - ->condition('csid', $posted_captcha_sid) - ->execute(); + // Invalidate CAPTCHA token to avoid reuse when the form is submitted. + if (!empty($form_state['submitted']) && !empty($posted_captcha_sid)) { + \Drupal::database()->update('captcha_sessions') + ->fields(['token' => NULL]) + ->condition('csid', $posted_captcha_sid) + ->execute(); + } } } else { -- GitLab