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

Template Route Variables incorrectly mapped when partial URLs supplied #3740

Open
jcogs-design opened this issue Sep 1, 2023 · 2 comments
Open

Comments

@jcogs-design
Copy link
Contributor

jcogs-design commented Sep 1, 2023

Description of the problem
Have a simple Template Route defined.

/{festival:regex[(test)]}/{edition:alpha_dash}/{event:alpha_dash}/{detail:alpha_dash}

This will route any URI beginning with /test to a nominated template.
At that template I have the following template code

<ul>
	<li>Festival: {segment:festival}</li>
	<li>Edition: {segment:edition}</li>
	<li>Event: {segment:event}</li>
	<li>Detail: {segment:detail}</li>
</ul>

If you hit that URL with four populated slugs you get the expected results:

https://domain.com/test/cats/are/cute
=>
Festival: test
Edition: cats
Event: are
Detail: cute

However if you hit the URL with only partially completed slugs you get some odd outcomes:

https://domain.com/test/cats-essentially-evil
=>
Festival: test
Edition: cats-essentially-
Event: evil
Detail:

and

https://domain.com/test/50
=>
Festival: test
Edition:
Event: 50
Detail:

So in one a slug is being split across two template route defined slugs, in the other the slug is being allocated to the "wrong" template route slug.

How To Reproduce
Steps to reproduce the behavior:

If you want to confirm steps are as described above. You can have a play with the test template here.

Environment Details:
EE6.4.14
php 8.1

Additional context
Appears to be another variant of this issue (that has been on this list for a long time, and weirdly is listed as an "enhancement" rather than a "bug"...).

@jcogs-design
Copy link
Contributor Author

Following a suggestion from Paul Bailey I applied the 'regex' route fix - if the fix is applied to all of the segments in the route, the route performs correctly.

/{festival:regex[(test)]}/{edition:regex[(.*)]}/{event:regex[(.*)]}/{detail:regex[(.*)]}

But not sure this is a viable long term solution - as if for no other reason it compels use of regex rule for each segment.

@PaulBaileyAtChan
Copy link

I can reproduce the behaviour described here. With a route extended to 5 segments:

/{base:regex[(testroute)]}/{a:alpha_dash}/{b:alpha_dash}/{c:alpha_dash}/{d:alpha_dash}

I get something maybe even odder when not all of the segments are present:

/testroute/cats-essentially-evil
=>
Base: testroute
A: cats-essentially-
B:
C: evil
D:

/testroute/50
=>
Base: testroute
A:
B:
C: 50
D:

There is a note in the docs which describes the regex hack, but this also doesn't seem to be accurate. None of the routes discussed here use static segments (the screenshot says "static variable", where I think it means "static segment"), but they still fall foul of the route parsing bug.

Screenshot 2023-09-01 at 12 57 25 PM

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

2 participants