8000 Minor fixes around parse_url() checks · symfony/symfony@1866ba2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1866ba2

Browse files
Minor fixes around parse_url() checks
1 parent e39f6a9 commit 1866ba2

File tree

11 files changed

+14
-15
lines changed

11 files changed

+14
-15
lines changed

src/Symfony/Bridge/Twig/Command/DebugCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ private function getRelativePath(string $path): string
562562

563563
private function isAbsolutePath(string $file): bool
564564
{
565-
return strspn($file, '/\\', 0, 1) || (\strlen($file) > 3 && ctype_alpha($file[0]) && ':' === $file[1] && strspn($file, '/\\', 2, 1)) || null !== parse_url($file, \PHP_URL_SCHEME);
565+
return strspn($file, '/\\', 0, 1) || (\strlen($file) > 3 && ctype_alpha($file[0]) && ':' === $file[1] && strspn($file, '/\\', 2, 1)) || parse_url($file, \PHP_URL_SCHEME);
566566
}
567567

568568
/**

src/Symfony/Bundle/FrameworkBundle/Controller/RedirectController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public function redirectAction(Request $request, string $route, bool $permanent
109109
*/
110110
public function urlRedirectAction(Request $request, string $path, bool $permanent = false, ?string $scheme = null, ?int $httpPort = null, ?int $httpsPort = null, bool $keepRequestMethod = false): Response
111111
{
112-
if ('' == $path) {
112+
if ('' === $path) {
113113
throw new HttpException($permanent ? 410 : 404);
114114
}
115115

src/Symfony/Component/Asset/UrlPackage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ private function getSslUrls(array $urls)
123123
foreach ($urls as $url) {
124124
if ('https://' === substr($url, 0, 8) || '//' === substr($url, 0, 2)) {
125125
$sslUrls[] = $url;
126-
} elseif (null === parse_url($url, \PHP_URL_SCHEME)) {
126+
} elseif (!parse_url($url, \PHP_URL_SCHEME)) {
127127
throw new InvalidArgumentException(sprintf('"%s" is not a valid URL.', $url));
128128
}
129129
}

src/Symfony/Component/BrowserKit/AbstractBrowser.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -366,11 +366,11 @@ public function request(string $method, string $uri, array $parameters = [], arr
366366

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

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

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

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

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

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

Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public static function fromString(string $cookie, ?string $url = null)
148148
];
149149

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

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

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

src/Symfony/Component/Config/FileLocator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ private function isAbsolutePath(string $file): bool
8484
&& ':' === $file[1]
8585
&& ('\\' === $file[2] || '/' === $file[2])
8686
)
87-
|| null !== parse_url($file, \PHP_URL_SCHEME)
87+
|| parse_url($file, \PHP_URL_SCHEME)
8888
) {
8989
return true;
9090
}

src/Symfony/Component/DependencyInjection/EnvVarProcessor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ public function getEnv(string $prefix, string $name, \Closure $getEnv)
259259
throw new RuntimeException(sprintf('Invalid URL in env var "%s".', $name));
260260
}
261261
if (!isset($params['scheme'], $params['host'])) {
262-
throw new RuntimeException(sprintf('Invalid URL env var "%s": schema and host expected, "%s" given.', $name, $env));
262+
throw new RuntimeException(sprintf('Invalid URL in env var "%s": scheme and host expected.', $name));
263263
}
264264
$params += [
265265
'port' => null,

src/Symfony/Component/DomCrawler/AbstractUriElement.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function __construct(\DOMElement $node, ?string $currentUri = null, ?stri
4646
$this->method = $method ? strtoupper($method) : null;
4747
$this->currentUri = $currentUri;
4848

49-
$elementUriIsRelative = null === parse_url(trim($this->getRawUri()), \PHP_URL_SCHEME);
49+
$elementUriIsRelative = !parse_url(trim($this->getRawUri()), \PHP_URL_SCHEME);
5050
$baseUriIsAbsolute = null !== $this->currentUri && \in_array(strtolower(substr($this->currentUri, 0, 4)), ['http', 'file']);
5151
if ($elementUriIsRelative && !$baseUriIsAbsolute) {
5252
throw new \InvalidArgumentException(sprintf('The URL of the element is relative, so you must define its base URI passing an absolute URL to the constructor of the "%s" class ("%s" was passed).', __CLASS__, $this->currentUri));

src/Symfony/Component/DomCrawler/Form.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,8 @@ public function getUri()
203203
$uri = parent::getUri();
204204

205205
if (!\in_array($this->getMethod(), ['POST', 'PUT', 'DELETE', 'PATCH'])) {
206-
$query = parse_url($uri, \PHP_URL_QUERY);
207206
$currentParameters = [];
208-
if ($query) {
207+
if ($query = parse_url($uri, \PHP_URL_QUERY)) {
209208
parse_str($query, $currentParameters);
210209
}
211210

src/Symfony/Component/Filesystem/Filesystem.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function copy(string $originFile, string $targetFile, bool $overwriteNewe
4444
$this->mkdir(\dirname($targetFile));
4545

4646
$doCopy = true;
47-
if (!$overwriteNewerFiles && null === parse_url($originFile, \PHP_URL_HOST) && is_file($targetFile)) {
47+
if (!$overwriteNewerFiles && !parse_url($originFile, \PHP_URL_HOST) && is_file($targetFile)) {
4848
$doCopy = filemtime($originFile) > filemtime($targetFile);
4949
}
5050

src/Symfony/Component/Templating/Loader/FilesystemLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ protected static function isAbsolutePath(string $file)
9696
&& ':' == $file[1]
9797
&& ('\\' == $file[2] || '/' == $file[2])
9898
)
99-
|| null !== parse_url($file, \PHP_URL_SCHEME)
99+
|| parse_url($file, \PHP_URL_SCHEME)
100100
) {
101101
return true;
102102
}

0 commit comments

Comments
 (0)
0