Skip to content

Commit 9b42217

Browse files
committed
Merge branch '6.4' into 7.3
* 6.4: Fix Warning: curl_multi_select(): timeout must be positive [PropertyInfo] Fix ReflectionExtractor handling of underscore-only property names ObjectNormalizer: allow null and scalar [Security] Fix `HttpUtils::createRequest()` when the context’s base URL isn’t empty [Serializer] fix Inherited properties normalization [OptionsResolver] Fix missing prototype key in nested error paths Bump Symfony version to 6.4.30 Update VERSION for 6.4.29 Update CHANGELOG for 6.4.29 [Yaml] Fix parsing of unquoted multiline scalars with comments or blank lines [Clock] Align MockClock::sleep() behavior with NativeClock for negative values [OptionsResolver] Ensure remove() also unsets deprecation status Remove review state for Belarusian translations (entries 141 and 142) [ExpressionLanguage] Compile numbers with var_export in Compiler::repr for thread-safety compatibility with ext-redis 6.3 [Serializer] Fix BackedEnumNormalizer behavior with partial denormalization
2 parents e79a63f + 5705ae1 commit 9b42217

File tree

2 files changed

+37
-4
lines changed

2 files changed

+37
-4
lines changed

HttpUtils.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,21 @@ public function createRequest(Request $request, string $path): Request
6868
if ($trustedProxies = Request::getTrustedProxies()) {
6969
Request::setTrustedProxies([], Request::getTrustedHeaderSet());
7070
}
71-
$newRequest = Request::create($this->generateUri($request, $path), 'get', [], $request->cookies->all(), [], $request->server->all());
72-
if ($trustedProxies) {
73-
Request::setTrustedProxies($trustedProxies, Request::getTrustedHeaderSet());
71+
72+
$context = $this->urlGenerator?->getContext();
73+
if ($baseUrl = $context?->getBaseUrl()) {
74+
$context->setBaseUrl('');
75+
}
76+
77+
try {
78+
$newRequest = Request::create($this->generateUri($request, $path), 'get', [], $request->cookies->all(), [], $request->server->all());
79+
} finally {
80+
if ($trustedProxies) {
81+
Request::setTrustedProxies($trustedProxies, Request::getTrustedHeaderSet());
82+
}
83+
if ($baseUrl) {
84+
$context->setBaseUrl($baseUrl);
85+
}
7486
}
7587

7688
static $setSession;

Tests/HttpUtilsTest.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,13 @@
1616
use Symfony\Component\HttpFoundation\Session\SessionInterface;
1717
use Symfony\Component\Routing\Exception\MethodNotAllowedException;
1818
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
19+
use Symfony\Component\Routing\Generator\UrlGenerator;
1920
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
2021
use Symfony\Component\Routing\Matcher\RequestMatcherInterface;
2122
use Symfony\Component\Routing\Matcher\UrlMatcherInterface;
2223
use Symfony\Component\Routing\RequestContext;
24+
use Symfony\Component\Routing\Route;
25+
use Symfony\Component\Routing\RouteCollection;
2326
use Symfony\Component\Security\Http\HttpUtils;
2427
use Symfony\Component\Security\Http\SecurityRequestAttributes;
2528

@@ -233,7 +236,7 @@ public static function provideSecurityRequestAttributes()
233236
];
234237
}
235238

236-
public function testCreateRequestHandlesTrustedHeaders()
239+
public function testCreateRequestFromPathHandlesTrustedHeaders()
237240
{
238241
Request::setTrustedProxies(['127.0.0.1'], Request::HEADER_X_FORWARDED_PREFIX);
239242

@@ -243,6 +246,24 @@ public function testCreateRequestHandlesTrustedHeaders()
243246
);
244247
}
245248

249+
public function testCreateRequestFromRouteHandlesTrustedHeaders()
250+
{
251+
Request::setTrustedProxies(['127.0.0.1'], Request::HEADER_X_FORWARDED_PREFIX);
252+
253+
$request = Request::create('/', server: ['HTTP_X_FORWARDED_PREFIX' => '/foo']);
254+
255+
$urlGenerator = new UrlGenerator(
256+
$routeCollection = new RouteCollection(),
257+
(new RequestContext())->fromRequest($request),
258+
);
259+
$routeCollection->add('root', new Route('/'));
260+
261+
$this->assertSame(
262+
'http://localhost/foo/',
263+
(new HttpUtils($urlGenerator))->createRequest($request, 'root')->getUri(),
264+
);
265+
}
266+
246267
public function testCheckRequestPath()
247268
{
248269
$utils = new HttpUtils($this->getUrlGenerator());

0 commit comments

Comments
 (0)