Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion aikido_zen/helpers/build_route_from_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

ULID_REGEX = re.compile(r"^[0-9A-HJKMNP-TV-Z]{26}$", re.I)
NUMBER_REGEX = re.compile(r"^\d+$")
DATE_REGEX = re.compile(r"^\d{4}-\d{2}-\d{2}|\d{2}-\d{2}-\d{4}$")
DATE_REGEX = re.compile(r"^(?:\d{4}-\d{2}-\d{2}|\d{2}-\d{2}-\d{4})$")
EMAIL_REGEX = re.compile(
r"^[a-zA-Z0-9.!#$%&\'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$"
)
Expand Down
10 changes: 10 additions & 0 deletions aikido_zen/helpers/build_route_from_url_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ def test_replace_dates():
assert build_route_from_url("/posts/01-05-2023") == "/posts/:date"


def test_does_not_replace_date_with_suffix():
# Segments that start with a date but have additional characters should not be replaced
assert (
build_route_from_url("/internal/2024-01-01-export")
== "/internal/2024-01-01-export"
)
assert build_route_from_url("/api/2023-12-31-backup") == "/api/2023-12-31-backup"
assert build_route_from_url("/data/01-01-2024-report") == "/data/01-01-2024-report"


def test_matches_arrays():
assert build_route_from_url("/posts/3,000") == "/posts/:array(number)"
assert build_route_from_url("/posts/0,1,2,3,4") == "/posts/:array(number)"
Expand Down
Loading