From 2c3fb22f68387f6a89e9866fef50a0b90b74061b Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Mon, 13 Feb 2023 15:47:05 +0800 Subject: [PATCH] Strip brackets and extra spaces --- staking_deposit/utils/validation.py | 2 ++ tests/test_utils/test_validation.py | 17 +++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/staking_deposit/utils/validation.py b/staking_deposit/utils/validation.py index a166816f..736a87f6 100644 --- a/staking_deposit/utils/validation.py +++ b/staking_deposit/utils/validation.py @@ -238,6 +238,8 @@ def validate_bls_withdrawal_credentials(bls_withdrawal_credentials: str) -> byte def normalize_input_list(input: str) -> Sequence[str]: + input = input.strip('[({})]') + input = re.sub(' +', ' ', input) return re.split(r'; |, | |,|;', input) diff --git a/tests/test_utils/test_validation.py b/tests/test_utils/test_validation.py index c0b9c89f..9b918462 100644 --- a/tests/test_utils/test_validation.py +++ b/tests/test_utils/test_validation.py @@ -5,6 +5,7 @@ from staking_deposit.exceptions import ValidationError from staking_deposit.utils.validation import ( + normalize_input_list, validate_int_range, validate_password_strength, ) @@ -43,3 +44,19 @@ def test_validate_int_range(num: Any, low: int, high: int, valid: bool) -> None: else: with pytest.raises(ValidationError): validate_int_range(num, low, high) + + +@pytest.mark.parametrize( + 'input, result', + [ + ('1', ['1']), + ('1,2,3', ['1', '2', '3']), + ('[1,2,3]', ['1', '2', '3']), + ('(1,2,3)', ['1', '2', '3']), + ('{1,2,3}', ['1', '2', '3']), + ('1 2 3', ['1', '2', '3']), + ('1 2 3', ['1', '2', '3']), + ] +) +def test_normalize_input_list(input, result): + assert normalize_input_list(input) == result