From 03cce39764429e07fbab9b989a1182a24578341d Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 22 Oct 2024 12:26:52 +0200 Subject: [PATCH] Minor fixes around parse_url() checks --- AbstractBrowser.php | 6 +++--- Cookie.php | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/AbstractBrowser.php b/AbstractBrowser.php index 785a216..487d234 100644 --- a/AbstractBrowser.php +++ b/AbstractBrowser.php @@ -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); } @@ -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); diff --git a/Cookie.php b/Cookie.php index bbec947..1a316cd 100644 --- a/Cookie.php +++ b/Cookie.php @@ -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)); } @@ -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; }