Skip to content

Commit

Permalink
Merge branch 'akhundMurad:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
attevaltojarvi authored Apr 19, 2024
2 parents 010a02e + 511582e commit 2762c85
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
16 changes: 16 additions & 0 deletions tests/test_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,22 @@ def test_validate_correct_prefix() -> None:
pytest.fail(str(exc))


def test_validate_correct_prefix_with_underscores() -> None:
prefix = "plov_good"

try:
validate_prefix(prefix)
except PrefixValidationException as exc:
pytest.fail(str(exc))


def test_validate_invalid_prefix_with_trailing_underscore() -> None:
prefix = "plov_bad_"

with pytest.raises(PrefixValidationException):
validate_prefix(prefix)


def test_validate_uppercase_prefix() -> None:
prefix = "Plov"

Expand Down
7 changes: 5 additions & 2 deletions typeid/validation.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import re

from typeid import base32
from typeid.constants import PREFIX_MAX_LEN, SUFFIX_LEN
from typeid.constants import SUFFIX_LEN
from typeid.errors import PrefixValidationException, SuffixValidationException


def validate_prefix(prefix: str) -> None:
if not prefix.islower() or not prefix.isascii() or len(prefix) > PREFIX_MAX_LEN or not prefix.isalpha():
# See https://github.com/jetify-com/typeid/tree/main/spec
if not re.match("^([a-z]([a-z_]{0,61}[a-z])?)?$", prefix):
raise PrefixValidationException(f"Invalid prefix: {prefix}.")


Expand Down

0 comments on commit 2762c85

Please sign in to comment.