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

Templates with a dash "-" in the path are no longer resolved #229

Closed
migonzalvar opened this issue Aug 21, 2023 · 3 comments
Closed

Templates with a dash "-" in the path are no longer resolved #229

migonzalvar opened this issue Aug 21, 2023 · 3 comments

Comments

@migonzalvar
Copy link

Issue Summary

I think I found a regression. After #223, templates with a dash "-" in the path are no longer resolved.

Steps to Reproduce

  1. Add a pattern with a dash, for example, patterns/components/quote-block/quote-block.html
  2. Navigate to http://localhost:8000/pattern-library/
  3. An error is shown: Reverse for 'display_pattern' with arguments '('patterns/components/quote-block/quote-block.html',)' not found. 1 pattern(s) tried: ['\\-/pattern\\-library/pattern/(?P<pattern_template_name>[\\w./-\\\\]+.html)$']

In version 1.0.0 it works just fine.

Technical details

In this snippet, I prove that the previous and current regexp does not behave the same with respect to dashes.

import re
template = "pattern/my-component.html"
previous = r"^pattern/(?P<pattern_template_name>[\w./-]+.html)$"
current = r"^pattern/(?P<pattern_template_name>[\w./-\\]+.html)$"
print("1.0.0", re.match(previous, template))
print("1.0.1", re.match(current, template))
$ python poc.py 
1.0.0 <re.Match object; span=(0, 25), match='pattern/my-component.html'>
1.0.1 None

Versions:

  • Python 3.8.10
  • Django 3.2.20

PS: Thank you for this awesome library.

@zerolab
Copy link
Member

zerolab commented Aug 22, 2023

We need to use r"^pattern/(?P<pattern_template_name>[\w./\-\\]+.html)$"

since \w./-\\ is interpreted as word, or . or range from / to \

@thibaudcolas
Copy link
Member

Ah, good catch @migonzalvar! While reviewing this I missed the significance of having the hyphen as the last item in the pattern.

@zerolab
Copy link
Member

zerolab commented Oct 25, 2023

Fixed in #230 and out in version 1.1

@zerolab zerolab closed this as completed Oct 25, 2023
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

No branches or pull requests

3 participants