Skip to content

Commit

Permalink
add format-suffix handling
Browse files Browse the repository at this point in the history
  • Loading branch information
wachterjohannes committed Aug 3, 2023
1 parent ea6267e commit a58f7c3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Controller/WebsiteRedirectController.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,12 @@ public function redirect(Request $request, RedirectRouteInterface $redirectRoute

$queryString = http_build_query($request->query->all());

$requestFormat = $request->getRequestFormat(null);
$formatSuffix = $requestFormat ? ('.' . $requestFormat) : '';

$url = [
$redirectRoute->getTarget(),
$formatSuffix,
false === strpos($redirectRoute->getTarget(), '?') ? '?' : '&',
$queryString,
];
Expand Down
3 changes: 2 additions & 1 deletion Routing/RedirectRouteProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,11 @@ public function getRouteCollectionForRequest(Request $request): RouteCollection
// server encodes the url and symfony does not encode it
// symfony decodes this data here https://github.com/symfony/symfony/blob/v5.2.3/src/Symfony/Component/Routing/Matcher/UrlMatcher.php#L88
$pathInfo = rawurldecode($request->getPathInfo());
$path = \str_replace('.' . $request->getRequestFormat(), '', $pathInfo);
$host = $request->getHost();

$routeCollection = new RouteCollection();
if (!$redirectRoute = $this->redirectRouteRepository->findEnabledBySource($pathInfo, $host)) {
if (!$redirectRoute = $this->redirectRouteRepository->findEnabledBySource($path, $host)) {
return $routeCollection;
}

Expand Down

0 comments on commit a58f7c3

Please sign in to comment.