Skip to content

check that url prefix starts with / #885

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 24, 2023
Merged
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
4 changes: 4 additions & 0 deletions src/idom/backend/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,7 @@ class CommonOptions:

url_prefix: str = ""
"""The URL prefix where IDOM resources will be served from"""

def __post_init__(self) -> None:
if self.url_prefix and not self.url_prefix.startswith("/"):
raise ValueError("Expected 'url_prefix' to start with '/'")
14 changes: 13 additions & 1 deletion tests/test_backend/test__common.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
import pytest

from idom import html
from idom.backend._common import traversal_safe_path, vdom_head_elements_to_html
from idom.backend._common import (
CommonOptions,
traversal_safe_path,
vdom_head_elements_to_html,
)


def test_common_options_url_prefix_starts_with_slash():
# no prefix specified
CommonOptions(url_prefix="")

with pytest.raises(ValueError, match="start with '/'"):
CommonOptions(url_prefix="not-start-withslash")


@pytest.mark.parametrize(
Expand Down