diff --git a/Util/UrlConvertor.php b/Util/UrlConvertor.php index aec5e5a..881ab69 100644 --- a/Util/UrlConvertor.php +++ b/Util/UrlConvertor.php @@ -86,22 +86,28 @@ public function isLocal(string $url): bool public function getUrlFromFilename(string $filename): string { try { - if (strpos($filename, $this->getMediaFolder()) !== false) { - return str_replace($this->getMediaFolder() . '/', $this->getMediaUrl(), $filename); + $mediaFolder = $this->getMediaFolder(); + $realMediaFolder = realpath($mediaFolder); + if (str_contains($filename, $realMediaFolder)) { + return str_replace($mediaFolder . '/', $this->getMediaUrl(), $filename); } } catch (FileSystemException|NoSuchEntityException $e) { throw new NotFoundException((string)__('Media folder does not exist')); } try { - if (strpos($filename, $this->getStaticFolder()) !== false) { + $staticFolder = $this->getStaticFolder(); + $realStaticFolder = realpath($staticFolder); + if (str_contains($filename, $realStaticFolder)) { return str_replace($this->getStaticFolder() . '/', $this->getStaticUrl(), $filename); } } catch (FileSystemException|NoSuchEntityException $e) { throw new NotFoundException((string)__('Static folder does not exist')); } - if (strpos($filename, $this->getBaseFolder()) !== false) { + $baseFolder = $this->getBaseFolder(); + $realBaseFolder = realpath($baseFolder); + if (str_contains($filename, $realBaseFolder)) { return str_replace($this->getBaseFolder() . '/', $this->getBaseUrl(), $filename); }