From 14efaea0bb61fe740a7807896625763764451335 Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Mon, 18 Mar 2013 14:12:28 -0400 Subject: [PATCH] send_message_backend: Reorganize subject argument checking. (imported from commit 80daa46f47e7e5279f746db89b3632eeadb27325) --- zephyr/views.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/zephyr/views.py b/zephyr/views.py index dccb1fb230..8d3d8d4aa8 100644 --- a/zephyr/views.py +++ b/zephyr/views.py @@ -866,24 +866,26 @@ def send_message_backend(request, user_profile, client, sender = user_profile if message_type_name == 'stream': - if subject_name is None: - return json_error("Missing subject") if len(message_to) > 1: return json_error("Cannot send to multiple streams") + stream_name = message_to[0].strip() if stream_name == "": return json_error("Stream can't be empty") - if subject_name == "": - return json_error("Subject can't be empty") if len(stream_name) > 30: return json_error("Stream name too long") - if len(subject_name) > MAX_SUBJECT_LENGTH: - return json_error("Subject too long") - if not valid_stream_name(stream_name): return json_error("Invalid stream name") + + if subject_name is None: + return json_error("Missing subject") + subject = subject_name.strip() + if subject == "": + return json_error("Subject can't be empty") + if len(subject) > MAX_SUBJECT_LENGTH: + return json_error("Subject too long") ## FIXME: Commented out temporarily while we figure out what we want - # if not valid_stream_name(subject_name): + # if not valid_stream_name(subject): # return json_error("Invalid subject name") stream = get_stream(stream_name, user_profile.realm) @@ -908,7 +910,7 @@ def send_message_backend(request, user_profile, client, message.content = message_content message.recipient = recipient if message_type_name == 'stream': - message.subject = subject_name + message.subject = subject if forged: # Forged messages come with a timestamp message.pub_date = timestamp_to_datetime(request.POST['time'])