Skip to content
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):
Comment on lines 259 to 260
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: Your fix won't work for exact_url

When you create a MenuItem with exact_url=True, the old behaviour will apply.

suggestion: Also add unquoting to this branch

matched = True
elif re.match("%s" % self.url, request.path):
elif re.match("%s" % unquote_plus(self.url), request.path):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: Why unquote_plus?

The only reason to use it instead of unquote is to parse HTML form values, but since we only work with URL path segments, I propose we just use unquote

suggestion:

Suggested change
elif re.match("%s" % unquote_plus(self.url), request.path):
elif re.match("%s" % unquote(self.url), request.path):

matched = True
return matched