Skip to content

Commit a5909c3

Browse files
committed
Ignore missing URL parts in NavItem activity check
Closes #169. If the URL of a navigation item is missing the scheme or the network location we ignore it in the check.
1 parent 05e8992 commit a5909c3

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/django_simple_nav/nav.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,9 @@ def get_active(self, request: HttpRequest) -> bool:
141141
parsed_request = urlparse(request.build_absolute_uri())
142142

143143
if (
144-
parsed_url.scheme != parsed_request.scheme
145-
or parsed_url.netloc != parsed_request.netloc
144+
(parsed_url.scheme and (parsed_url.scheme != parsed_request.scheme))
145+
or
146+
(parsed_url.netloc and (parsed_url.netloc != parsed_request.netloc))
146147
):
147148
return False
148149

tests/test_navitem.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,14 @@ def test_active_different_domain(rf):
156156
assert item.get_active(req) is False
157157

158158

159+
def test_active_no_scheme_no_netloc(rf):
160+
item = NavItem(title=..., url="/test/")
161+
162+
req = rf.get("/test")
163+
164+
assert item.get_active(req) is True
165+
166+
159167
@pytest.mark.parametrize("append_slash", [True, False])
160168
def test_active_append_slash_setting(append_slash, rf):
161169
item = NavItem(title=..., url="http://testserver/test")

0 commit comments

Comments
 (0)