Skip to content

Commit f7d7e29

Browse files
authored
check that url prefix starts with / (#885)
1 parent 981fd43 commit f7d7e29

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/idom/backend/_common.py

+4
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,7 @@ class CommonOptions:
128128

129129
url_prefix: str = ""
130130
"""The URL prefix where IDOM resources will be served from"""
131+
132+
def __post_init__(self) -> None:
133+
if self.url_prefix and not self.url_prefix.startswith("/"):
134+
raise ValueError("Expected 'url_prefix' to start with '/'")

tests/test_backend/test__common.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
11
import pytest
22

33
from idom import html
4-
from idom.backend._common import traversal_safe_path, vdom_head_elements_to_html
4+
from idom.backend._common import (
5+
CommonOptions,
6+
traversal_safe_path,
7+
vdom_head_elements_to_html,
8+
)
9+
10+
11+
def test_common_options_url_prefix_starts_with_slash():
12+
# no prefix specified
13+
CommonOptions(url_prefix="")
14+
15+
with pytest.raises(ValueError, match="start with '/'"):
16+
CommonOptions(url_prefix="not-start-withslash")
517

618

719
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)