Skip to content

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

Open
ajarzyn wants to merge 1 commit into
jazzband:masterfrom
ajarzyn:master
Open

Bug fix: Submenus with spaces are not matched against url.#150
ajarzyn wants to merge 1 commit into
jazzband:masterfrom
ajarzyn:master

Conversation

@ajarzyn

@ajarzyn ajarzyn commented Mar 6, 2025

Copy link
Copy Markdown

Fixes #149

@ajarzyn

ajarzyn commented May 16, 2025

Copy link
Copy Markdown
Author

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

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

kytta commented May 20, 2025

Copy link
Copy Markdown
Member

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

@kytta kytta left a comment

Copy link
Copy Markdown
Member

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

Comment thread simple_menu/menu.py
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
Copy Markdown
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 thread simple_menu/menu.py
Comment on lines 259 to 260
if self.exact_url:
if re.match(f"{self.url}$", request.path):

Copy link
Copy Markdown
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