Skip to content

Commit

Permalink
fix: check that parse_url returns a string for paths
Browse files Browse the repository at this point in the history
  • Loading branch information
carlalexander committed Dec 15, 2021
1 parent 9acbe4a commit b0d59ca
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/Subscriber/AssetsSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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();
Expand Down

0 comments on commit b0d59ca

Please sign in to comment.