From b0d59ca4a9d1a9b2fba8b4ac909f1a104111119e Mon Sep 17 00:00:00 2001 From: Carl Alexander Date: Wed, 15 Dec 2021 13:06:45 -0500 Subject: [PATCH] fix: check that `parse_url` returns a string for paths --- src/Subscriber/AssetsSubscriber.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Subscriber/AssetsSubscriber.php b/src/Subscriber/AssetsSubscriber.php index 2e22ec0..a1b4c79 100644 --- a/src/Subscriber/AssetsSubscriber.php +++ b/src/Subscriber/AssetsSubscriber.php @@ -162,7 +162,9 @@ public function replaceUrlsInContent(string $content): string $contentUrls = $urls->filter(function (string $url) use ($siteHost) { return parse_url($url, PHP_URL_HOST) === $siteHost; })->filter(function (string $url) { - return 0 === stripos(parse_url($url, PHP_URL_PATH), $this->contentDirectoryName); + $path = parse_url($url, PHP_URL_PATH); + + return is_string($path) && 0 === stripos($path, $this->contentDirectoryName); }); // Point all non-uploads "/wp-content" URLs to the assets URL. @@ -174,7 +176,9 @@ public function replaceUrlsInContent(string $content): string // Point all URLs to "/wp-content/uploads" to the uploads URL. $uploadsUrls = $contentUrls->filter(function (string $url) use ($uploadsDirectory) { - return 0 === stripos(parse_url($url, PHP_URL_PATH), $uploadsDirectory); + $path = parse_url($url, PHP_URL_PATH); + + return is_string($path) && 0 === stripos($path, $uploadsDirectory); })->mapWithKeys(function (string $url) use ($uploadsDirectory) { return [$url => $this->rewriteUploadsUrl(sprintf('%%https?://[^/]*%s(.*)%%', $uploadsDirectory), $url)]; })->all();