Skip to content

Commit 5302eae

Browse files
Merge branch '5.4' into 6.4
* 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
2 parents 65b8a96 + 6ad5e27 commit 5302eae

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

HttpClientTrait.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,8 @@ private static function jsonEncode(mixed $value, ?int $flags = null, int $maxDep
557557
*/
558558
private static function resolveUrl(array $url, ?array $base, array $queryDefaults = []): array
559559
{
560+
$givenUrl = $url;
561+
560562
if (null !== $base && '' === ($base['scheme'] ?? '').($base['authority'] ?? '')) {
561563
throw new InvalidArgumentException(sprintf('Invalid "base_uri" option: host or scheme is missing in "%s".', implode('', $base)));
562564
}
@@ -610,6 +612,10 @@ private static function resolveUrl(array $url, ?array $base, array $queryDefault
610612
$url['query'] = null;
611613
}
612614

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

Tests/HttpClientTestCase.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\HttpClient\Tests;
1313

1414
use Symfony\Component\HttpClient\Exception\ClientException;
15+
use Symfony\Component\HttpClient\Exception\InvalidArgumentException;
1516
use Symfony\Component\HttpClient\Exception\TransportException;
1617
use Symfony\Component\HttpClient\Internal\ClientState;
1718
use Symfony\Component\HttpClient\Response\StreamWrapper;
@@ -451,6 +452,16 @@ public function testNullBody()
451452
$this->expectNotToPerformAssertions();
452453
}
453454

455+
public function testMisspelledScheme()
456+
{
457+
$httpClient = $this->getHttpClient(__FUNCTION__);
458+
459+
$this->expectException(InvalidArgumentException::class);
460+
$this->expectExceptionMessage('Invalid URL: host is missing in "http:/localhost:8057/".');
461+
462+
$httpClient->request('GET', 'http:/localhost:8057/');
463+
}
464+
454465
/**
455466
* @dataProvider getRedirectWithAuthTests
456467
*/

Tests/HttpClientTraitTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,6 @@ public function testResolveUrl(string $base, string $url, string $expected)
175175
public static function provideResolveUrl(): array
176176
{
177177
return [
178-
[self::RFC3986_BASE, 'http:h', 'http:h'],
179178
[self::RFC3986_BASE, 'g', 'http://a/b/c/g'],
180179
[self::RFC3986_BASE, './g', 'http://a/b/c/g'],
181180
[self::RFC3986_BASE, 'g/', 'http://a/b/c/g/'],
@@ -229,7 +228,6 @@ public static function provideResolveUrl(): array
229228
['http://u:p@a/b/c/d;p?q', '.', 'http://u:p@a/b/c/'],
230229
// path ending with slash or no slash at all
231230
['http://a/b/c/d/', 'e', 'http://a/b/c/d/e'],
232-
['http:no-slash', 'e', 'http:e'],
233231
// falsey relative parts
234232
[self::RFC3986_BASE, '//0', 'http://0/'],
235233
[self::RFC3986_BASE, '0', 'http://a/b/c/0'],

0 commit comments

Comments
 (0)