diff --git a/cuenca_validations/types/helpers.py b/cuenca_validations/types/helpers.py index 9cd87452..6736fdd0 100644 --- a/cuenca_validations/types/helpers.py +++ b/cuenca_validations/types/helpers.py @@ -1,4 +1,5 @@ import datetime as dt +import random import uuid from base64 import urlsafe_b64encode from typing import Callable, Optional, Union @@ -12,7 +13,10 @@ def uuid_field(prefix: str = '') -> Callable[[], str]: def base64_uuid_func() -> str: - return prefix + urlsafe_b64encode(uuid.uuid4().bytes).decode()[:-2] + base64_str = urlsafe_b64encode(uuid.uuid4().bytes).decode()[:-2] + rnd = str(random.randint(0, 9)) + sanitized = base64_str.replace('-', rnd).replace('_', rnd) + return prefix + sanitized return base64_uuid_func diff --git a/cuenca_validations/version.py b/cuenca_validations/version.py index 4afeab12..c6d8fc9b 100644 --- a/cuenca_validations/version.py +++ b/cuenca_validations/version.py @@ -1 +1 @@ -__version__ = '2.1.21' +__version__ = '2.1.22' diff --git a/tests/test_helpers.py b/tests/test_helpers.py index 99791514..5c426244 100644 --- a/tests/test_helpers.py +++ b/tests/test_helpers.py @@ -27,3 +27,10 @@ def test_multiple_generators(): assert uuid1.startswith('CA') assert uuid2.startswith('TR') assert uuid1 != uuid2 + + +def test_sanitized_uuid(): + generator = uuid_field('US') + uuid_str = generator() + assert "-" not in uuid_str + assert "_" not in uuid_str