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

Symfony 3.3 routing automatic trailing slash missing #23004

Closed
dubaksk opened this issue Jun 1, 2017 · 13 comments
Closed

Symfony 3.3 routing automatic trailing slash missing #23004

dubaksk opened this issue Jun 1, 2017 · 13 comments

Comments

@dubaksk
Copy link

dubaksk commented Jun 1, 2017

Q A
Bug report? yes
Feature request? yes
BC Break report? no
RFC? ?
Symfony version 3.3.0

After upgrading to Symfony 3.3.0 we realised, that when we had something like this:

     * @Route(
     *     "/c/{articleId}/",
     *     name="article_simple_no_alias",
     *     methods={"GET"},
     *     requirements={"articleId": "[0-9]+?"}
     * )

when I put into browser URL without trailing slash, I was redirected automatically to URL with trailing slash. And it worked also other way.

In profiler -> request -> parameters, I could see:

_controller	
"Symfony\Bundle\FrameworkBundle\Controller\RedirectController::urlRedirectAction"
permanent	true
scheme	null

It was ok. But since 3.3 version this feature is missing and we could not find it in changelog if it was change intentionally. Now the page without trailing slash is giving us error 404 and we really don't want to go through whole project and update all routes, so this trailing slash would be optional..

@mvrhov
Copy link

mvrhov commented Jun 1, 2017

This is probably because of the huge speed optimizations that have been done on the routing component. Ping @frankdejonge

@frankdejonge
Copy link
Contributor

@dubaksk does this happen only in the prod env or also on your dev env?

@dubaksk
Copy link
Author

dubaksk commented Jun 1, 2017

@frankdejonge It happens on all environments. We do not consider this happen due to different environment set up.

@frankdejonge
Copy link
Contributor

Ok, so then we know it's not because of the matcher dumper optimisation because those aren't used in dev. We could look into the RouteCompiler next, I'll check that out.

@frankdejonge
Copy link
Contributor

Hmm, it seems the matcher dumper is actually used, digging into that now.

@frankdejonge
Copy link
Contributor

@dubaksk what version did you upgrade from?

@frankdejonge
Copy link
Contributor

@dubaksk from what I see those redirects only happen for HEAD requests, or for routes that haven't defined methods. Which is both a little wonky. In my perception it should be done on non HEAD and GET routes. The code that determines it dates back 6 years, so it popping up now is a bit odd (https://github.com/symfony/symfony/blame/master/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php#L241). Perhaps this was a side-effect from another commit.

@frankdejonge
Copy link
Contributor

@dubaksk I've created a PR, perhaps you can check it out? See above.

@dubaksk
Copy link
Author

dubaksk commented Jun 1, 2017

@frankdejonge Great, so you allowed also GET method. Give me a some time to verify the fix. I will let you know.

@frankdejonge
Copy link
Contributor

@dubaksk 👍

@dubaksk
Copy link
Author

dubaksk commented Jun 1, 2017

@frankdejonge We verified your pull request and it's working as before on 3.2.9 version 👍
So now we don't have to do create something hacky like this:

     * @Route(
     *     "/c/{articleId}/{articleAlias}{trailingSlash}",
     *     name="sport_article_simple",
     *     methods={"GET"},
     *     defaults={"page": 1, "trailingSlash" = "/"},
     *     requirements={"articleId": "[0-9]+?", "articleAlias": "[a-zA-Z0-9\-\_]+?", "trailingSlash" = "[/]{0,1}"}
     * )

So what's the scenario now? We have to wait until pull request is accepted and then you will release 3.3.X version with this fix?

@frankdejonge
Copy link
Contributor

@dubaksk another option for now would be to include the HEAD method in addition to the GET method. But for the actual fix we'd need to wait for 3.3.1 like you mentioned.

@dubaksk
Copy link
Author

dubaksk commented Jun 1, 2017

@frankdejonge Yep, this will be the way. Thank you guys and mostly you @frankdejonge for such a prompt solution.

@weaverryan weaverryan added this to the 3.3 milestone Jun 1, 2017
fabpot added a commit that referenced this issue Jun 1, 2017
…(frankdejonge)

This PR was merged into the 3.3 branch.

Discussion
----------

[Routing] Allow GET requests to be redirected. Fixes #23004

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

GET requests didn't get the same redirect treatment as HEAD requests. I've also added tests cases for all the different trailing/non-trailing slash situations.

Commits
-------

71d4e36 [Routing] Allow GET requests to be redirected. Fixes #23004
@fabpot fabpot closed this as completed Jun 1, 2017
fabpot added a commit that referenced this issue Jun 1, 2017
* 3.3: (31 commits)
  Using FQ name for PHP_VERSION_ID
  [EventDispatcher] Handle laziness internally instead of relying on ClosureProxyArgument
  Fix CacheCollectorPass priority
  [Form] Fix \IntlDateFormatter timezone parameter usage to bypass PHP bug #66323
  [Routing] Allow GET requests to be redirected. Fixes #23004
  [DI] Deal with inlined non-shared services
  [Cache] Ignore missing annotations.php
  [DI] Autowiring exception thrown when inlined service is removed
  Improving deprecation message when hitting the "deprecated type" lookup, but an alias is available
  Harden the debugging of Twig filters and functions
  Fixing a bug where an autowiring exception was thrown even when that service was removed
  Remove extra arg in call to TraceableAdapter::start()
  Support unknown compiler log format
  [Config] Allow empty globs
  Fix decorating TagAware adapters in dev
  [Profiler] Fix clicking on links inside toggle
  [Profiler] Fix text selection on exception pages
  bumped Symfony version to 3.3.1
  updated VERSION for 3.3.0
  updated CHANGELOG for 3.3.0
  ...
fabpot added a commit that referenced this issue Jun 1, 2017
* 3.4: (31 commits)
  Using FQ name for PHP_VERSION_ID
  [EventDispatcher] Handle laziness internally instead of relying on ClosureProxyArgument
  Fix CacheCollectorPass priority
  [Form] Fix \IntlDateFormatter timezone parameter usage to bypass PHP bug #66323
  [Routing] Allow GET requests to be redirected. Fixes #23004
  [DI] Deal with inlined non-shared services
  [Cache] Ignore missing annotations.php
  [DI] Autowiring exception thrown when inlined service is removed
  Improving deprecation message when hitting the "deprecated type" lookup, but an alias is available
  Harden the debugging of Twig filters and functions
  Fixing a bug where an autowiring exception was thrown even when that service was removed
  Remove extra arg in call to TraceableAdapter::start()
  Support unknown compiler log format
  [Config] Allow empty globs
  Fix decorating TagAware adapters in dev
  [Profiler] Fix clicking on links inside toggle
  [Profiler] Fix text selection on exception pages
  bumped Symfony version to 3.3.1
  updated VERSION for 3.3.0
  updated CHANGELOG for 3.3.0
  ...
@fabpot fabpot mentioned this issue Jun 5, 2017
ostrolucky pushed a commit to ostrolucky/symfony that referenced this issue Mar 25, 2018
* 3.3: (31 commits)
  Using FQ name for PHP_VERSION_ID
  [EventDispatcher] Handle laziness internally instead of relying on ClosureProxyArgument
  Fix CacheCollectorPass priority
  [Form] Fix \IntlDateFormatter timezone parameter usage to bypass PHP bug #66323
  [Routing] Allow GET requests to be redirected. Fixes symfony#23004
  [DI] Deal with inlined non-shared services
  [Cache] Ignore missing annotations.php
  [DI] Autowiring exception thrown when inlined service is removed
  Improving deprecation message when hitting the "deprecated type" lookup, but an alias is available
  Harden the debugging of Twig filters and functions
  Fixing a bug where an autowiring exception was thrown even when that service was removed
  Remove extra arg in call to TraceableAdapter::start()
  Support unknown compiler log format
  [Config] Allow empty globs
  Fix decorating TagAware adapters in dev
  [Profiler] Fix clicking on links inside toggle
  [Profiler] Fix text selection on exception pages
  bumped Symfony version to 3.3.1
  updated VERSION for 3.3.0
  updated CHANGELOG for 3.3.0
  ...
ostrolucky pushed a commit to ostrolucky/symfony that referenced this issue Mar 25, 2018
* 3.4: (31 commits)
  Using FQ name for PHP_VERSION_ID
  [EventDispatcher] Handle laziness internally instead of relying on ClosureProxyArgument
  Fix CacheCollectorPass priority
  [Form] Fix \IntlDateFormatter timezone parameter usage to bypass PHP bug #66323
  [Routing] Allow GET requests to be redirected. Fixes symfony#23004
  [DI] Deal with inlined non-shared services
  [Cache] Ignore missing annotations.php
  [DI] Autowiring exception thrown when inlined service is removed
  Improving deprecation message when hitting the "deprecated type" lookup, but an alias is available
  Harden the debugging of Twig filters and functions
  Fixing a bug where an autowiring exception was thrown even when that service was removed
  Remove extra arg in call to TraceableAdapter::start()
  Support unknown compiler log format
  [Config] Allow empty globs
  Fix decorating TagAware adapters in dev
  [Profiler] Fix clicking on links inside toggle
  [Profiler] Fix text selection on exception pages
  bumped Symfony version to 3.3.1
  updated VERSION for 3.3.0
  updated CHANGELOG for 3.3.0
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants