From bcba08ae85cd3da09f63b8eeb368d7449ade4a7c Mon Sep 17 00:00:00 2001 From: gabino Date: Wed, 19 Nov 2025 15:41:10 -0600 Subject: [PATCH 1/3] Enhance uuid_field function to sanitize output by replacing '-' and '_' with 'A' and 'B' --- cuenca_validations/types/helpers.py | 4 +++- cuenca_validations/version.py | 2 +- tests/test_helpers.py | 7 +++++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/cuenca_validations/types/helpers.py b/cuenca_validations/types/helpers.py index 9cd87452..07a71006 100644 --- a/cuenca_validations/types/helpers.py +++ b/cuenca_validations/types/helpers.py @@ -12,7 +12,9 @@ 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] + sanitized = base64_str.replace('-', 'A').replace('_', 'B') + 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..a6fb047c 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 From 7aea820eb2a54dc46977f24a52ababb36217efa9 Mon Sep 17 00:00:00 2001 From: gabino Date: Wed, 19 Nov 2025 15:47:22 -0600 Subject: [PATCH 2/3] Fix test_sanitized_uuid to assert that '_' is not present in the generated UUID string --- tests/test_helpers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_helpers.py b/tests/test_helpers.py index a6fb047c..5c426244 100644 --- a/tests/test_helpers.py +++ b/tests/test_helpers.py @@ -33,4 +33,4 @@ def test_sanitized_uuid(): generator = uuid_field('US') uuid_str = generator() assert "-" not in uuid_str - assert "-" not in uuid_str + assert "_" not in uuid_str From 5f0584fe1792e6ee36daeb42d35cc65c754def86 Mon Sep 17 00:00:00 2001 From: gabino Date: Wed, 19 Nov 2025 19:13:46 -0600 Subject: [PATCH 3/3] Update uuid_field function to replace '-' and '_' with random digits for enhanced uniqueness --- cuenca_validations/types/helpers.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cuenca_validations/types/helpers.py b/cuenca_validations/types/helpers.py index 07a71006..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 @@ -13,7 +14,8 @@ def uuid_field(prefix: str = '') -> Callable[[], str]: def base64_uuid_func() -> str: base64_str = urlsafe_b64encode(uuid.uuid4().bytes).decode()[:-2] - sanitized = base64_str.replace('-', 'A').replace('_', 'B') + rnd = str(random.randint(0, 9)) + sanitized = base64_str.replace('-', rnd).replace('_', rnd) return prefix + sanitized return base64_uuid_func