Skip to content

Commit

Permalink
Minor fixes around parse_url() checks
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-grekas committed Oct 22, 2024
1 parent dd5d1a7 commit 03cce39
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions AbstractBrowser.php
Original file line number Diff line number Diff line change
Expand Up @@ -366,11 +366,11 @@ public function request(string $method, string $uri, array $parameters = [], arr

$server = array_merge($this->server, $server);

if (!empty($server['HTTP_HOST']) && null === parse_url($originalUri, \PHP_URL_HOST)) {
if (!empty($server['HTTP_HOST']) && !parse_url($originalUri, \PHP_URL_HOST)) {
$uri = preg_replace('{^(https?\://)'.preg_quote($this->extractHost($uri)).'}', '${1}'.$server['HTTP_HOST'], $uri);
}

if (isset($server['HTTPS']) && null === parse_url($originalUri, \PHP_URL_SCHEME)) {
if (isset($server['HTTPS']) && !parse_url($originalUri, \PHP_URL_SCHEME)) {
$uri = preg_replace('{^'.parse_url($uri, \PHP_URL_SCHEME).'}', $server['HTTPS'] ? 'https' : 'http', $uri);
}

Expand All @@ -382,7 +382,7 @@ public function request(string $method, string $uri, array $parameters = [], arr
$server['HTTP_HOST'] = $this->extractHost($uri);
}

$server['HTTPS'] = 'https' == parse_url($uri, \PHP_URL_SCHEME);
$server['HTTPS'] = 'https' === parse_url($uri, \PHP_URL_SCHEME);

$this->internalRequest = new Request($uri, $method, $parameters, $files, $this->cookieJar->allValues($uri), $server, $content);

Expand Down
4 changes: 2 additions & 2 deletions Cookie.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public static function fromString(string $cookie, ?string $url = null)
];

if (null !== $url) {
if ((false === $urlParts = parse_url($url)) || !isset($urlParts['host'])) {
if (false === ($urlParts = parse_url($url)) || !isset($urlParts['host'])) {
throw new \InvalidArgumentException(sprintf('The URL "%s" is not valid.', $url));
}

Expand All @@ -161,7 +161,7 @@ public static function fromString(string $cookie, ?string $url = null)

if ('secure' === strtolower($part)) {
// Ignore the secure flag if the original URI is not given or is not HTTPS
if (!$url || !isset($urlParts['scheme']) || 'https' != $urlParts['scheme']) {
if (null === $url || !isset($urlParts['scheme']) || 'https' != $urlParts['scheme']) {
continue;
}

Expand Down

0 comments on commit 03cce39

Please sign in to comment.