Skip to content

Commit

Permalink
Merge pull request #81 from sandstein/master
Browse files Browse the repository at this point in the history
Solves issue #80
  • Loading branch information
jissereitsma authored Dec 4, 2024
2 parents 4d36e40 + 838794b commit f746ccd
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions Util/UrlConvertor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit f746ccd

Please sign in to comment.