Skip to content

Commit

Permalink
Merge pull request #81 from jdecool/feature/twig-extension-path
Browse files Browse the repository at this point in the history
Ensure clean path in Twig extension
  • Loading branch information
jdecool authored Jul 4, 2016
2 parents d27e6c3 + 3c03128 commit 949ac20
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 949ac20

Please sign in to comment.