From 3d04f5f7385b3faaf555528f87b37848b5ccb571 Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Fri, 14 Feb 2014 10:25:31 -0500 Subject: [PATCH] Use check_list instead of json_to_list. (imported from commit 9ead12bc2a4744b94a747ca27054124aacde7ae4) --- zerver/lib/validator.py | 11 ++++++----- zerver/tornadoviews.py | 8 ++++---- zerver/views/__init__.py | 2 +- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/zerver/lib/validator.py b/zerver/lib/validator.py index 6ab2e5b226..7efdf4c90a 100644 --- a/zerver/lib/validator.py +++ b/zerver/lib/validator.py @@ -49,11 +49,12 @@ def check_list(sub_validator, length=None): if length is not None and length != len(val): return '%s should have exactly %d items' % (var_name, length) - for i, item in enumerate(val): - vname = '%s[%d]' % (var_name, i) - error = sub_validator(vname, item) - if error: - return error + if sub_validator: + for i, item in enumerate(val): + vname = '%s[%d]' % (var_name, i) + error = sub_validator(vname, item) + if error: + return error return None return f diff --git a/zerver/tornadoviews.py b/zerver/tornadoviews.py index fc77ea6194..e0f89db957 100644 --- a/zerver/tornadoviews.py +++ b/zerver/tornadoviews.py @@ -5,10 +5,10 @@ from zerver.models import get_client from zerver.decorator import asynchronous, \ authenticated_json_post_view, internal_notify_view, RespondAsynchronously, \ - has_request_variables, json_to_list, json_to_dict, REQ + has_request_variables, json_to_dict, REQ from zerver.lib.response import json_success, json_error -from zerver.lib.validator import check_bool +from zerver.lib.validator import check_bool, check_list, check_string from zerver.tornado_callbacks import process_notification from zerver.lib.event_queue import allocate_client_descriptor, get_client_descriptor @@ -48,9 +48,9 @@ def get_events_backend(request, user_profile, handler = None, queue_id = REQ(default=None), apply_markdown = REQ(default=False, validator=check_bool), all_public_streams = REQ(default=False, validator=check_bool), - event_types = REQ(default=None, converter=json_to_list), + event_types = REQ(default=None, validator=check_list(check_string)), dont_block = REQ(default=False, validator=check_bool), - narrow = REQ(default=[], converter=json_to_list), + narrow = REQ(default=[], validator=check_list(None)), lifespan_secs = REQ(default=0, converter=int)): if user_client is None: user_client = request.client diff --git a/zerver/views/__init__.py b/zerver/views/__init__.py index 92e6480228..fd9ad2021a 100644 --- a/zerver/views/__init__.py +++ b/zerver/views/__init__.py @@ -55,7 +55,7 @@ from zerver.lib.validator import check_string, check_list, check_dict, check_int from zerver.decorator import require_post, \ authenticated_api_view, authenticated_json_post_view, \ has_request_variables, authenticated_json_view, \ - to_non_negative_int, json_to_dict, json_to_list, json_to_bool, \ + to_non_negative_int, json_to_dict, json_to_bool, \ JsonableError, get_user_profile_by_email, REQ, require_realm_admin, \ RequestVariableConversionError from zerver.lib.avatar import avatar_url, get_avatar_url