Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
update_user_custom_profile_data: Validate data type correctly.
Anders Kaseorg475fc5910fbd
diff --git a/zerver/tests/test_custom_profile_data.py b/zerver/tests/test_custom_profile_data.pyindex bde5afbc1b7..701703e00f5 100644--- a/zerver/tests/test_custom_profile_data.py+++ b/zerver/tests/test_custom_profile_data.py@@ -525,8 +525,10 @@ class UpdateCustomProfileFieldTest(CustomProfileFieldTestCase):})# Update value of field- result = self.client_patch("/json/users/me/profile_data",- {'data': ujson.dumps(data)})+ result = self.client_patch(+ "/json/users/me/profile_data",+ {"data": ujson.dumps([{"id": f["id"], "value": f["value"]} for f in data])},+ )self.assert_json_success(result)iago = self.example_user('iago')diff --git a/zerver/views/custom_profile_fields.py b/zerver/views/custom_profile_fields.pyindex 96941837efa..883dd96ef6e 100644--- a/zerver/views/custom_profile_fields.py+++ b/zerver/views/custom_profile_fields.py@@ -26,6 +26,8 @@ from zerver.lib.validator import (check_dict,check_int,check_list,+ check_string,+ check_union,validate_choice_field_data,)from zerver.models import CustomProfileField, UserProfile, custom_profile_fields_for_realm@@ -176,10 +178,17 @@ def remove_user_custom_profile_data(request: HttpRequest, user_profile: UserProf@human_users_only@has_request_variablesdef update_user_custom_profile_data(- request: HttpRequest,- user_profile: UserProfile,- data: List[Dict[str, Union[int, str, List[int]]]]=REQ(validator=check_list(- check_dict([('id', check_int)])))) -> HttpResponse:+ request: HttpRequest,+ user_profile: UserProfile,+ data: List[Dict[str, Union[int, str, List[int]]]] = REQ(+ validator=check_list(+ check_dict(+ [('id', check_int)],+ value_validator=check_union([check_int, check_string, check_list(check_int)]),+ ),+ )+ ),+) -> HttpResponse:validate_user_custom_profile_data(user_profile.realm.id, data)do_update_user_custom_profile_data_if_changed(user_profile, data)