Skip to content

Commit

Permalink
Merge branch '5.4' into 6.4
Browse files Browse the repository at this point in the history
* 5.4:
  add German translations for the Week constraint messages
  sync Week constraint messages translations
  [Validator] Add `D` regex modifier in relevant validators
  [Validator] Add French translation for the `Week` constraint
  reject malformed URLs with a meaningful exception
  [Mime] Add tests on constraints
  • Loading branch information
nicolas-grekas committed Aug 13, 2024
2 parents 65b8a96 + 6ad5e27 commit 5302eae
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
6 changes: 6 additions & 0 deletions HttpClientTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,8 @@ private static function jsonEncode(mixed $value, ?int $flags = null, int $maxDep
*/
private static function resolveUrl(array $url, ?array $base, array $queryDefaults = []): array
{
$givenUrl = $url;

if (null !== $base && '' === ($base['scheme'] ?? '').($base['authority'] ?? '')) {
throw new InvalidArgumentException(sprintf('Invalid "base_uri" option: host or scheme is missing in "%s".', implode('', $base)));
}
Expand Down Expand Up @@ -610,6 +612,10 @@ private static function resolveUrl(array $url, ?array $base, array $queryDefault
$url['query'] = null;
}

if (null !== $url['scheme'] && null === $url['authority']) {
throw new InvalidArgumentException(\sprintf('Invalid URL: host is missing in "%s".', implode('', $givenUrl)));
}

return $url;
}

Expand Down
11 changes: 11 additions & 0 deletions Tests/HttpClientTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Component\HttpClient\Tests;

use Symfony\Component\HttpClient\Exception\ClientException;
use Symfony\Component\HttpClient\Exception\InvalidArgumentException;
use Symfony\Component\HttpClient\Exception\TransportException;
use Symfony\Component\HttpClient\Internal\ClientState;
use Symfony\Component\HttpClient\Response\StreamWrapper;
Expand Down Expand Up @@ -451,6 +452,16 @@ public function testNullBody()
$this->expectNotToPerformAssertions();
}

public function testMisspelledScheme()
{
$httpClient = $this->getHttpClient(__FUNCTION__);

$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Invalid URL: host is missing in "http:/localhost:8057/".');

$httpClient->request('GET', 'http:/localhost:8057/');
}

/**
* @dataProvider getRedirectWithAuthTests
*/
Expand Down
2 changes: 0 additions & 2 deletions Tests/HttpClientTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ public function testResolveUrl(string $base, string $url, string $expected)
public static function provideResolveUrl(): array
{
return [
[self::RFC3986_BASE, 'http:h', 'http:h'],
[self::RFC3986_BASE, 'g', 'http://a/b/c/g'],
[self::RFC3986_BASE, './g', 'http://a/b/c/g'],
[self::RFC3986_BASE, 'g/', 'http://a/b/c/g/'],
Expand Down Expand Up @@ -229,7 +228,6 @@ public static function provideResolveUrl(): array
['http://u:p@a/b/c/d;p?q', '.', 'http://u:p@a/b/c/'],
// path ending with slash or no slash at all
['http://a/b/c/d/', 'e', 'http://a/b/c/d/e'],
['http:no-slash', 'e', 'http:e'],
// falsey relative parts
[self::RFC3986_BASE, '//0', 'http://0/'],
[self::RFC3986_BASE, '0', 'http://a/b/c/0'],
Expand Down

0 comments on commit 5302eae

Please sign in to comment.