Skip to content

Conversation

ajarzyn
Copy link

@ajarzyn ajarzyn commented Mar 6, 2025

Fixes #149

@ajarzyn
Copy link
Author

ajarzyn commented May 16, 2025

@kytta hey could you please check this PR.
Thanks.

@kytta kytta self-requested a review May 20, 2025 16:16
@kytta
Copy link
Member

kytta commented May 20, 2025

Code looks good; will test later today when I get home

Copy link
Member

@kytta kytta left a comment

Choose a reason for hiding this comment

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

The code works, but only for inexact URL matches (the default). See my comments for more info

@@ -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):
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):

Comment on lines 259 to 260
if self.exact_url:
if re.match(f"{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.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Spaces in title breaks menu structure
2 participants