From 56ee52699a264da86940e2505e28c4d6ec4bf818 Mon Sep 17 00:00:00 2001 From: n9k Date: Fri, 17 Jun 2022 00:36:13 +0000 Subject: [PATCH] Nojs chat form: on failure truncate long comments --- anonstream/routes/nojs.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/anonstream/routes/nojs.py b/anonstream/routes/nojs.py index 772fbe3..0a6c836 100644 --- a/anonstream/routes/nojs.py +++ b/anonstream/routes/nojs.py @@ -101,14 +101,13 @@ async def nojs_chat_form(user): @with_user_from(request) async def nojs_chat_form_redirect(user): comment = (await request.form).get('comment', '') - if len(comment) > CONFIG['CHAT_COMMENT_MAX_LENGTH']: - comment = '' - if comment: - state_id = add_state(user, comment=comment) + state_id = add_state( + user, + comment=comment[:CONFIG['CHAT_COMMENT_MAX_LENGTH']], + ) else: state_id = None - return redirect(url_for('nojs_chat_form', token=user['token'], state=state_id)) @current_app.post('/chat/message') @@ -123,7 +122,11 @@ async def nojs_submit_message(user): verification_happened = verify(user, digest, answer) except BadCaptcha as e: notice, *_ = e.args - state_id = add_state(user, notice=notice, comment=comment) + state_id = add_state( + user, + notice=notice, + comment=comment[:CONFIG['CHAT_COMMENT_MAX_LENGTH']], + ) else: nonce = form.get('nonce', '') try: @@ -137,7 +140,11 @@ async def nojs_submit_message(user): ) except Rejected as e: notice, *_ = e.args - state_id = add_state(user, notice=notice, comment=comment) + state_id = add_state( + user, + notice=notice, + comment=comment[:CONFIG['CHAT_COMMENT_MAX_LENGTH']], + ) else: state_id = None if message_was_added: