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

[Routing] fix trailing slash redirection when using RedirectableUrlMatcher #29297

Merged
merged 1 commit into from Nov 26, 2018

Conversation

nicolas-grekas
Copy link
Member

@nicolas-grekas nicolas-grekas commented Nov 23, 2018

Q A
Branch? 3.4
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #29287
License MIT
Doc PR -

This fixes #29287 by considering that the behavior of the dumped matcher is the correct one: lower priority routes never impact previous ones. I think it's what makes the most sense because that's what requires the most local knowledge to understand what's going on (ie that's the less surprising behavior).

Copy link
Contributor

@HeahDude HeahDude left a comment

Choose a reason for hiding this comment

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

Your arguments convinced me, 👍

@Tobion
Copy link
Member

Tobion commented Nov 24, 2018

👎 #29287 (comment)

@nicolas-grekas nicolas-grekas force-pushed the routing-fix branch 2 times, most recently from 31e4c6e to 77b4188 Compare November 24, 2018 08:50
@nicolas-grekas
Copy link
Member Author

Behavior a) is what most people use since a very long time. Changing it would break symfony.com. We cannot break URLs without being 200% sure we should do it. The logic in the php dumper that provides behavior a) is non-trivial. I wouldn't call it a mistake but a design choice. Feature-wise, the behavior makes a lot of sense to me: later routes should not impact previous routes.
(http/https redirections are very different: nobody deals with them URL per URL.)

I did ask because that was not obvious at first, but the arguments we gathered are sound. b) is the bug.

@Tobion
Copy link
Member

Tobion commented Nov 24, 2018

To me a) is a bug . Why no just fix symfony.com until more people complain about this? Then we can reevaluate re-adding a bogus feature that only existed because of implementation details.

@nicolas-grekas
Copy link
Member Author

The patch for symfony.com will be totally unexpected, looking a lot like a workaround for a WTF behavior in core.

Here is the route in practice:

  • /blog/ => map to specific controller
  • [...] many unrelated routes
  • /{page} => fallback route to mini CMS-like pages.

The fact that the fallback exists is totally unrelated to the fact that /blog redirects to /blog/. /{page} is certainly not the correct fallback for it. The redirection is.

People will complain if we change the current behavior. e.g. symfony.com would break. And I'm sure many others will also.

@Tobion
Copy link
Member

Tobion commented Nov 24, 2018

You can either make {page} placeholder not accept "blog" (which seems like a logical solution to prevent collision with the blog route) or create a /blog route explicitly that redirects to /blog/.

@nicolas-grekas
Copy link
Member Author

Sure I can, but there are more routes than just /blog/ - an exclusion list is going to be a significant maintenance burden - one that we don't have to do right now. Same for the explicit redirection.

@fabpot
Copy link
Member

fabpot commented Nov 24, 2018

I understand you both @Tobion and @nicolas-grekas. I would slightly prefer b) if we were talking about a new routing system, but in any case, we cannot introduce a BC break on routes now (if symfony.com is affected, we can be sure that we will have tons of people angry of we change the behavior, even of we do so only in 4.2/master).

So, to me, a) is the only option at this stage (maybe a note in the docs is in order here).

@Tobion
Copy link
Member

Tobion commented Nov 24, 2018

Go ahead then. But you probably want to implement the same logic for the opposite redirection which will get pretty ugly https://symfony.com/blog/new-in-symfony-4-1-smarter-url-redirections

@nicolas-grekas
Copy link
Member Author

@Tobion agreed, that's done in #29298

@Tobion
Copy link
Member

Tobion commented Nov 24, 2018

Actually which this logic in place, it might be claener to have the route compiler generate a regex with an optional trailing slash in the first place. That seems more logical to me than changing the regex later on. This way debug:router makes it also more self-explaining.
When the matcher does not support redirection: just match with and without trailing slash. When it has redirection support just redirect to the correct one.

@nicolas-grekas
Copy link
Member Author

nicolas-grekas commented Nov 24, 2018

The fact that the original path contains a trailing slash or not is required to decide which is the canonical path we redirect to. I'd prefer keeping the current way to do so to make the patch as light as possible.

@nicolas-grekas nicolas-grekas modified the milestones: 2.8, 3.4 Nov 26, 2018
@nicolas-grekas nicolas-grekas changed the base branch from 2.8 to 3.4 November 26, 2018 08:41
@nicolas-grekas
Copy link
Member Author

nicolas-grekas commented Nov 26, 2018

Now targeting 3.4, let 2.8 in peace.

@nicolas-grekas nicolas-grekas merged commit dc4c3f6 into symfony:3.4 Nov 26, 2018
nicolas-grekas added a commit that referenced this pull request Nov 26, 2018
…ctableUrlMatcher (nicolas-grekas)

This PR was merged into the 3.4 branch.

Discussion
----------

[Routing] fix trailing slash redirection when using RedirectableUrlMatcher

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #29287
| License       | MIT
| Doc PR        | -

This fixes #29287 by considering that the behavior of the dumped matcher is the correct one: lower priority routes never impact previous ones. I think it's what makes the most sense because that's what requires the most local knowledge to understand what's going on (ie that's the less surprising behavior).

Commits
-------

dc4c3f6 [Routing] fix trailing slash redirection when using RedirectableUrlMatcher
nicolas-grekas added a commit that referenced this pull request Nov 26, 2018
…ctableUrlMatcher (nicolas-grekas)

This PR was merged into the 4.1 branch.

Discussion
----------

[Routing] fix trailing slash redirection when using RedirectableUrlMatcher

| Q             | A
| ------------- | ---
| Branch?       | 4.1
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #29297
| License       | MIT
| Doc PR        | -

This is #29297 for 4.1

Commits
-------

6968000 [Routing] fix trailing slash redirection when using RedirectableUrlMatcher
@nicolas-grekas nicolas-grekas deleted the routing-fix branch November 26, 2018 12:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants