Skip to content

Commit bcba08a

Browse files
committed
Enhance uuid_field function to sanitize output by replacing '-' and '_' with 'A' and 'B'
1 parent 93122b7 commit bcba08a

3 files changed

Lines changed: 11 additions & 2 deletions

File tree

cuenca_validations/types/helpers.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212

1313
def uuid_field(prefix: str = '') -> Callable[[], str]:
1414
def base64_uuid_func() -> str:
15-
return prefix + urlsafe_b64encode(uuid.uuid4().bytes).decode()[:-2]
15+
base64_str = urlsafe_b64encode(uuid.uuid4().bytes).decode()[:-2]
16+
sanitized = base64_str.replace('-', 'A').replace('_', 'B')
17+
return prefix + sanitized
1618

1719
return base64_uuid_func
1820

cuenca_validations/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '2.1.21'
1+
__version__ = '2.1.22'

tests/test_helpers.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,10 @@ def test_multiple_generators():
2727
assert uuid1.startswith('CA')
2828
assert uuid2.startswith('TR')
2929
assert uuid1 != uuid2
30+
31+
32+
def test_sanitized_uuid():
33+
generator = uuid_field('US')
34+
uuid_str = generator()
35+
assert "-" not in uuid_str
36+
assert "-" not in uuid_str

0 commit comments

Comments
 (0)