Skip to content

Commit

Permalink
Merge branch '6.2' into 6.3
Browse files Browse the repository at this point in the history
* 6.2:
  [Security] Allow custom scheme to be used as redirection URIs
  [Validator] Do not mock metadata factory on debug command tests
  [HttpKernel][WebProfilerBundle] Fix search feature
  update Intl component to take into account B-variant when converting Alpha3 to Alpha2. fixing issue with Darwin.
  [VarDumper] Fix dumping `ArrayObject` with `DumpDataCollector`
  [VarDumper] Add tests to demonstrate a bug when dumping ArrayObject with full stack fmk
  [DebugBundle][FrameworkBundle] Fix using the framework without the Console component
  [FrameworkBundle] Add missing monolog channel tag to the `messenger:failed:retry` command
  fetch all known ChoiceType values at once
  [RateLimiter] fix incorrect retryAfter of FixedWindow
  Fix Finder phpdoc
  • Loading branch information
nicolas-grekas committed Jul 13, 2023
2 parents bb42256 + d6231db commit 04d6b86
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
4 changes: 3 additions & 1 deletion HttpUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,9 @@ public function checkRequestPath(Request $request, string $path): bool
*/
public function generateUri(Request $request, string $path): string
{
if (str_starts_with($path, 'http') || !$path) {
$url = parse_url($path);

if ('' === $path || isset($url['scheme'], $url['host'])) {
return $path;
}

Expand Down
49 changes: 49 additions & 0 deletions Tests/HttpUtilsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,54 @@ public function testCreateRedirectResponseWithRequestsDomain()
$this->assertTrue($response->isRedirect('http://localhost/blog'));
}

/**
* @dataProvider validRequestDomainUrls
*/
public function testCreateRedirectResponse(?string $domainRegexp, string $path, string $expectedRedirectUri)
{
$utils = new HttpUtils($this->getUrlGenerator(), null, $domainRegexp);
$response = $utils->createRedirectResponse($this->getRequest(), $path);

$this->assertTrue($response->isRedirect($expectedRedirectUri));
$this->assertEquals(302, $response->getStatusCode());
}

public static function validRequestDomainUrls()
{
return [
'/foobar' => [
null,
'/foobar',
'http://localhost/foobar',
],
'http://symfony.com/ without domain regex' => [
null,
'http://symfony.com/',
'http://symfony.com/',
],
'http://localhost/blog with #^https?://symfony\.com$#i' => [
'#^https?://symfony\.com$#i',
'http://symfony.com/blog',
'http://symfony.com/blog',
],
'http://localhost/blog with #^https?://%s$#i' => [
'#^https?://%s$#i',
'http://localhost/blog',
'http://localhost/blog',
],
'custom scheme' => [
null,
'android-app://com.google.android.gm/',
'android-app://com.google.android.gm/',
],
'custom scheme with all URL components' => [
null,
'android-app://foo:bar@www.example.com:8080/software/index.html?lite=true#section1',
'android-app://foo:bar@www.example.com:8080/software/index.html?lite=true#section1',
],
];
}

/**
* @dataProvider badRequestDomainUrls
*/
Expand All @@ -77,6 +125,7 @@ public static function badRequestDomainUrls()
['http:/\\pirate.net/foo'],
['http:\\/pirate.net/foo'],
['http://////pirate.net/foo'],
['http:///foo'],
];
}

Expand Down

0 comments on commit 04d6b86

Please sign in to comment.