Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Resolved #924 where template routing did not work properly with optional segments #4477

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

Open
wants to merge 2 commits into
base: 7.dev
Choose a base branch
from

Conversation

intoeetive
Copy link
Contributor

Resolved #924 where template routing did not work properly with optional segments

@intoeetive intoeetive added the Bug: Accepted Bug has been confirmed, is reproducible, and ready to work on. label Sep 14, 2024
@intoeetive intoeetive added this to the 7.x milestone Sep 14, 2024
Copy link
Contributor

@bryannielsen bryannielsen left a comment

Choose a reason for hiding this comment

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

@intoeetive I haven't tested this but looking at the code would it be better to do rtrim and just focus on the trailing slash like your comment says?

Copy link

@adster101 adster101 left a comment

Choose a reason for hiding this comment

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

Tested locally on 7.4.11 and seems to work. My template route is:

/(uk|london|manchester|bristol|brighton)/search/{page:pagination}

When I apply the patch urls with optional segments are working as expected:

http://localhost:3000/london/search
http://localhost:3000/london/search/P20

whereas without the patch http://localhost:3000/london/search resolves to a 404.

@adster101
Copy link

On further testing it seems as though this fix doesn't fully work. It seems to work okay as outlined above but with a more complex route it seems not to work.

For example I have this template route:

/(uk|london|manchester|bristol|brighton)/search/{segment_3:alpha_dash}/{page:pagination}

With the fix applied the following urls still give a 404 not found error

/london/search
/manchester/search
/bristol/search

@intoeetive
Copy link
Contributor Author

@adster101 thank you for reporting this. Pushed the change that would hopefully fix the issue (you would need to re-save the routes to make it work)

@bryannielsen need a good review here as well as some testing. The regex wasn't build correctly to consider multiple optional segments - previously, the slash was marked as optional, but the segment stayed required. I also tried to make it avoid extra unnecessary group nesting.

@intoeetive intoeetive modified the milestones: 7.x, 7.5.12 May 14, 2025
@TomJaeger TomJaeger modified the milestones: 7.5.12, 7.5.13 May 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug: Accepted Bug has been confirmed, is reproducible, and ready to work on.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Long-standing issue with template route matching where final segment is optional
4 participants