-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Query string dot is replaced with underscore by trailing slash URL redirection #29664
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
Comments
It's because we decided to use |
@wgorczyca Thanks for sharing. API Platform's
But maybe |
(For information, for the moment I have done something like https://stackoverflow.com/questions/52705684/how-to-disable-trailing-slash-redirect-in-symfony-4-1/52786096#52786096 because a 404 error (like in 3.4) is still better than a redirect with corrupted query parameters...) |
Note that the automatic conversion of dots into underscores is a PHP behavior ... which could finally be changed/removed in PHP 8: https://externals.io/message/106213 |
Having |
@javiereguiluz But in this precise case the PHP behavior only bites because Symfony does trailing-slash redirection by using I found related #28806 @stof I wouldn't expect a change to be needed at that level |
Sorry to dig up such old topics but I encountered the issue while doing the ecphp/cas-bundle and working with API Platform. I have found a pretty nice solution for us and I made a bundle out of it: https://github.com/loophp/unaltered-psr-http-message-bridge-bundle |
…ecting (nicolas-grekas) This PR was merged into the 3.4 branch. Discussion ---------- [FrameworkBundle] preserve dots in query-string when redirecting | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #29664 | License | MIT | Doc PR | - Commits ------- fcc0e2c [FrameworkBundle] preserve dots in query-string when redirecting
…ecting (nicolas-grekas) This PR was merged into the 4.4 branch. Discussion ---------- [FrameworkBundle] preserve dots in query-string when redirecting | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #29664 | License | MIT | Doc PR | - Requires #37270 to pass. Commits ------- 3d0d59d [FrameworkBundle] preserve dots in query-string when redirecting
…oes the same as `parse_str()` but preserves dots in variable names (nicolas-grekas) This PR was merged into the 5.2-dev branch. Discussion ---------- [HttpFoundation] add `HeaderUtils::parseQuery()`: it does the same as `parse_str()` but preserves dots in variable names | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - Inspired by symfony/psr-http-message-bridge#80 /cc @drupol Related to #9009, #29664, #26220 but also api-platform/core#509 and https://www.drupal.org/project/drupal/issues/2984272 /cc @dunglas @alexpott Commits ------- dd81e32 [HttpFoundation] add `HeaderUtils::parseQuery()`: it does the same as `parse_str()` but preserves dots in variable names
Symfony version(s) affected: 4.1.9, 4.2.1
Description
Having defined a route without trailing slash in the path,
accessing the URL with a trailing slash automatically redirects to the URL without the trailing slash, but also replaces dots with underscores in the query string parameters names (if any).
How to reproduce
TL;DR:
Given my
localhost
app defines a route for method GET for path/foos
(not/foos/
)When a client requests (GET) the URL
http://localhost/foos/?nested.prop=bar
Then I expect the client is redirected to
http://localhost/foos?nested.prop=bar
but actually the client is redirected to
http://localhost/foos?nested_prop=bar
More details:
Given the following controller (note: no trailing slash after "foos"):
src/Controller/FooController.php
Then
http://localhost/foos?nested.prop=bar displays:
$request->getUri()
http://localhost/foos?nested_prop=bar
$request->getSchemeAndHttpHost().$request->getRequestUri()
http://localhost/foos?nested.prop=bar
$request->getQueryString()
nested_prop=bar
$request->server->get("QUERY_STRING")
nested.prop=bar
(i.e.
nested.prop
is transformed tonested_prop
but there are ways to get the original query string).http://localhost/foos/?nested.prop=bar (note: trailing slash after "foos") redirects (301) to http://localhost/foos?nested_prop=bar with trailing slash removed but also dot replaced with underscore, which thus displays:
$request->getUri()
http://localhost/foos?nested_prop=bar
$request->getSchemeAndHttpHost().$request->getRequestUri()
http://localhost/foos?nested_prop=bar
$request->getQueryString()
nested_prop=bar
$request->server->get("QUERY_STRING")
nested_prop=bar
i.e. we only have
nested_prop
, the original query string has been lost.Additional context
With 3.4.20,
http://localhost/foos?nested.prop=bar displays:
$request->getUri()
http://localhost/foos?nested.prop=bar
$request->getSchemeAndHttpHost().$request->getRequestUri()
http://localhost/foos?nested.prop=bar
$request->getQueryString()
nested.prop=bar
$request->server->get("QUERY_STRING")
nested.prop=bar
(i.e.
nested.prop
was preserved).http://localhost/foos/?nested.prop=bar (note: trailing slash after "foos") gives a 404 error
No route found for "GET /foos/"
(no automatic redirect).In all cases,
$request->query->get("nested.prop")
isnull
(not defined) (with 4.1, 4.2 and even 3.4), and we have to use$request->query->get("nested_prop")
(or parse the original query string) to get"bar"
.The real project uses API Platform, which auto-generates resource routes (without trailing slash) and parses the original query string to get nested filters (with dots). The calls with trailing slash are from automated REST clients.
The text was updated successfully, but these errors were encountered: