Mark Sapiro pushed to branch master at GNU Mailman / Mailman Core
Commits: 340cb816 by Abhilash Raj at 2018-05-30T04:22:05Z Empty string in List-of-strings-validator is interpreted as empty string. - - - - - 0851c7c8 by Abhilash Raj at 2018-05-30T15:55:14Z pep8 fixes. - - - - - 7670605f by Mark Sapiro at 2018-05-30T21:37:12Z Merge branch 'master' into 'aa-list' # Conflicts: # src/mailman/docs/NEWS.rst - - - - - 79d8f4e7 by Mark Sapiro at 2018-05-30T23:29:58Z Merge branch 'aa-list' into 'master' Empty string in List-of-strings-validator is interpreted as empty string. See merge request mailman/mailman!395 - - - - - 3 changed files: - src/mailman/docs/NEWS.rst - src/mailman/rest/tests/test_validator.py - src/mailman/rest/validator.py Changes: ===================================== src/mailman/docs/NEWS.rst ===================================== --- a/src/mailman/docs/NEWS.rst +++ b/src/mailman/docs/NEWS.rst @@ -156,9 +156,13 @@ REST * Expose ``MailingList.respond_to_post_request`` through REST API. (Closes #420) * Add a new API ``lists/find`` which returns all the lists related to a subscriber. It optionally allows filtering based on a role. (See !388) +* ``IAcceptableAliasSet`` resource now interprets an empty string ('') as an + empty list ([]). This can be used to clear the list of acceptable aliases of a + MailingList in a PATCH or PUT request, without having to use a DELETE request. * Expose ``MailingList.require_explicit_destination`` through REST API. (Closes #484) + 3.1.0 -- "Between The Wheels" ============================= (2017-05-25) ===================================== src/mailman/rest/tests/test_validator.py ===================================== --- a/src/mailman/rest/tests/test_validator.py +++ b/src/mailman/rest/tests/test_validator.py @@ -42,6 +42,10 @@ class TestValidators(unittest.TestCase): list_of_strings_validator(['ant', 'bee', 'cat']), ['ant', 'bee', 'cat']) + def test_list_of_strings_validator_empty_list(self): + # This validator should return an empty list for an empty string input. + self.assertEqual(list_of_strings_validator(''), []) + def test_integer_ge_zero_validator_invalid(self): self.assertRaises(ValueError, integer_ge_zero_validator, 'foo') self.assertRaises(ValueError, integer_ge_zero_validator, '-1') ===================================== src/mailman/rest/validator.py ===================================== --- a/src/mailman/rest/validator.py +++ b/src/mailman/rest/validator.py @@ -93,6 +93,14 @@ def language_validator(code): @public def list_of_strings_validator(values): """Turn a list of things, or a single thing, into a list of unicodes.""" + # There is no good way to pass around an empty list through HTTP API, so, + # we consider an empty string as an empty list, which can easily be passed + # around. This is a contract between Core and Postorius. This also fixes a + # bug where an empty string ('') would be interpreted as a valid value [''] + # to create a singleton list, instead of empty list, which in later stages + # would create other problems. + if values is '': + return [] if not isinstance(values, (list, tuple)): values = [values] for value in values: View it on GitLab: https://gitlab.com/mailman/mailman/compare/7c008ea5c5b25b4c52b2bab9a1b5a9b53c8f7beb...79d8f4e742f0983d0442d64a9ab1739ca4799228 -- View it on GitLab: https://gitlab.com/mailman/mailman/compare/7c008ea5c5b25b4c52b2bab9a1b5a9b53c8f7beb...79d8f4e742f0983d0442d64a9ab1739ca4799228 You're receiving this email because of your account on gitlab.com.
_______________________________________________ Mailman-checkins mailing list Mailman-checkins@python.org Unsubscribe: https://mail.python.org/mailman/options/mailman-checkins/archive%40jab.org