Skip to content

Commit 4364d1e

Browse files
committed
✨ Add SafeQueryStr type alias for safe URL query parameters
1 parent 5581d6e commit 4364d1e

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

packages/models-library/src/models_library/basic_types.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from re import Pattern
44
from typing import Annotated, ClassVar, Final, TypeAlias
55

6+
import annotated_types
67
from common_library.basic_types import BootModeEnum, BuildTargetEnum, LogLevel
78
from pydantic import Field, HttpUrl, PositiveInt, StringConstraints
89
from pydantic_core import core_schema
@@ -70,6 +71,20 @@
7071
UUIDStr: TypeAlias = Annotated[str, StringConstraints(pattern=UUID_RE)]
7172

7273

74+
SafeQueryStr: TypeAlias = Annotated[
75+
str,
76+
StringConstraints(
77+
max_length=512, # Reasonable limit for query parameters to avoid overflows
78+
strip_whitespace=True,
79+
),
80+
annotated_types.doc(
81+
"""
82+
A string that is safe to use in URLs and query parameters.
83+
""",
84+
),
85+
]
86+
87+
7388
# non-empty bounded string used as identifier
7489
# e.g. "123" or "name_123" or "fa327c73-52d8-462a-9267-84eeaf0f90e3" but NOT ""
7590
_ELLIPSIS_CHAR: Final[str] = "..."

0 commit comments

Comments
 (0)