Skip to content

Commit f09ba83

Browse files
Work around parse_url() bug
1 parent 4d547e5 commit f09ba83

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

HttpClientTrait.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,10 @@ private static function resolveUrl(array $url, ?array $base, array $queryDefault
515515
private static function parseUrl(string $url, array $query = [], array $allowedSchemes = ['http' => 80, 'https' => 443]): array
516516
{
517517
if (false === $parts = parse_url($url)) {
518-
throw new InvalidArgumentException(sprintf('Malformed URL "%s".', $url));
518+
if ('/' !== ($url[0] ?? '') || false === $parts = parse_url($url.'#')) {
519+
throw new InvalidArgumentException(sprintf('Malformed URL "%s".', $url));
520+
}
521+
unset($parts['fragment']);
519522
}
520523

521524
if ($query) {

NativeHttpClient.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ private static function createRedirectResolver(array $options, string $host, ?ar
416416

417417
[$host, $port] = self::parseHostPort($url, $info);
418418

419-
if (false !== (parse_url($location, \PHP_URL_HOST) ?? false)) {
419+
if (false !== (parse_url($location.'#', \PHP_URL_HOST) ?? false)) {
420420
// Authorization and Cookie headers MUST NOT follow except for the initial host name
421421
$requestHeaders = $redirectHeaders['host'] === $host ? $redirectHeaders['with_auth'] : $redirectHeaders['no_auth'];
422422
$requestHeaders[] = 'Host: '.$host.$port;

0 commit comments

Comments
 (0)