From 3c031283ed90f0927a6f591e51b534c5a0ee9212 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20DECOOL?= Date: Mon, 4 Jul 2016 14:32:37 +0200 Subject: [PATCH] Ensure clean path in Twig extension --- Twig/Extension/FileManagementExtension.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Twig/Extension/FileManagementExtension.php b/Twig/Extension/FileManagementExtension.php index f5488c9..20605d4 100644 --- a/Twig/Extension/FileManagementExtension.php +++ b/Twig/Extension/FileManagementExtension.php @@ -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) @@ -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, '/') ); } }