Skip to content
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

Bug fix: Submenus with spaces are not matched against url. #150

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 example/accounts/menus.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ def profile_title(request):
icon=f'{i}-circle')
for i in range(1, 4)
]

# Test sub menu with space
submenu_items.append(MenuItem(f"Page with space", reverse('accounts:space_test')))

Menu.add_item("user", MenuItem("Subpages",
reverse('accounts:subpage', kwargs={'i': 1}),
icon="menu-app",
Expand Down
1 change: 1 addition & 0 deletions example/accounts/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@
path('super/', views.SuperOnlyView.as_view(), name='super_only'),

path("sub/<int:i>/", views.SubPageView.as_view(), name='subpage'),
path("space test", views.SubPageView.as_view(), name='space_test'),
]
4 changes: 3 additions & 1 deletion simple_menu/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from django.conf import settings
from django.utils.text import slugify

from urllib.parse import unquote_plus


class Menu:
"""
Expand Down Expand Up @@ -257,6 +259,6 @@ def match_url(self, request):
if self.exact_url:
if re.match(f"{self.url}$", request.path):
matched = True
elif re.match("%s" % self.url, request.path):
elif re.match("%s" % unquote_plus(self.url), request.path):
matched = True
return matched