Commit 30ba4c77 authored by Jérome Perrin's avatar Jérome Perrin

ERP5Form/CaptchaField: prevent infinite loop

This probably happened only in the test, but it's safer not to retry
for ever.
parent f2da92ba
......@@ -197,8 +197,15 @@ class CaptchaWidget(Widget.TextWidget):
provider = CaptchaProviderFactory.getProvider(captcha_type)
(captcha_key, captcha_answer) = provider.generate(field)
portal_sessions = field.getPortalObject().portal_sessions
while not self.add_captcha(portal_sessions, md5(captcha_key).hexdigest(), captcha_answer):
(captcha_key, captcha_answer) = provider.generate(field)
retries = 10
while retries:
if self.add_captcha(portal_sessions, md5(captcha_key).hexdigest(), captcha_answer):
(captcha_key, captcha_answer) = provider.generate(field)
break
retries = retries - 1
else:
raise RuntimeError("Error adding captcha")
captcha_field = provider.getHTML(field, captcha_key)
key_field = Widget.render_element("input",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment