Skip to content

Commit

Permalink
Ensure clean path in Twig extension
Browse files Browse the repository at this point in the history
  • Loading branch information
Jérémy DECOOL committed Jul 4, 2016
1 parent d27e6c3 commit 3c03128
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions Twig/Extension/FileManagementExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ public function filepath($entity, $propertyName)
return null;
}

return $this->webDirectory.$filePath;
return sprintf('%s/%s',
rtrim($this->webDirectory, '/'),
ltrim($filePath, '/')
);
}

public function imagepath($entity, $propertyName, $format, $updateCache = true)
Expand Down Expand Up @@ -82,10 +85,10 @@ private function getUrl($path)
return null;
}

return sprintf('%s://%s%s',
return sprintf('%s://%s/%s',
$this->generator->getContext()->getScheme(),
$this->generator->getContext()->getHost(),
$path
rtrim($this->generator->getContext()->getHost(), '/'),
ltrim($path, '/')
);
}
}
Expand Down

0 comments on commit 3c03128

Please sign in to comment.