Skip to content

Commit 3351fdb

Browse files
committed
Safeguard against parse_url() failure
Just in case this ever happens…
1 parent 49ef74c commit 3351fdb

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

root-files/opt/flownative/sitemap-crawler/sitemap-crawler.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ public function crawl(): void
6969
}
7070

7171
$parsedFirstUrl = parse_url($firstUrl);
72+
if ($parsedFirstUrl === false) {
73+
$this->log('Could not parse first URL: ' . $firstUrl);
74+
exit(1);
75+
}
7276
$internalFirstUrl = $this->internalBaseUrl . $parsedFirstUrl['path'] . (isset($parsedFirstUrl['query']) ? '?' . $parsedFirstUrl['query'] : '');
7377

7478
$this->log(sprintf('Checking connectivity by retrieving %s, simulating host %s', $internalFirstUrl, $parsedFirstUrl['host']));
@@ -115,6 +119,10 @@ public function crawl(): void
115119
$curlHandles = [];
116120
foreach ($chunk as $i => $url) {
117121
$parsedUrl = parse_url($url);
122+
if ($parsedUrl === false) {
123+
$this->log('Could not parse URL: ' . $url);
124+
continue;
125+
}
118126
$url = $this->internalBaseUrl . $parsedUrl['path'] . (isset($parsedUrl['query']) ? '?' . $parsedUrl['query'] : '');
119127

120128
$curlHandles[$i] = curl_init($url);

0 commit comments

Comments
 (0)