diff --git a/src/Interpolator.php b/src/Interpolator.php index 9ff2a85..16ea61f 100644 --- a/src/Interpolator.php +++ b/src/Interpolator.php @@ -24,11 +24,15 @@ class Interpolator implements InterpolatorInterface * * @return string */ - public function interpolate($string, AttachmentInterface $attachment, $styleName = '') + public function interpolate($string, AttachmentInterface $attachment, $styleName = '', $shouldUrlencode = false) { foreach ($this->interpolations() as $key => $value) { if (strpos($string, $key) !== false) { - $string = preg_replace("/$key\b/", $this->$value($attachment, $styleName), $string); + $v = $this->$value($attachment, $styleName); + if ($shouldUrlencode) { + $v = join(DIRECTORY_SEPARATOR, array_map('rawurlencode', explode(DIRECTORY_SEPARATOR, $v))); + } + $string = preg_replace("/$key\b/", $v, $string); } } diff --git a/src/Storage/Filesystem.php b/src/Storage/Filesystem.php index 75a0b02..d2e134e 100644 --- a/src/Storage/Filesystem.php +++ b/src/Storage/Filesystem.php @@ -34,7 +34,7 @@ public function __construct(Attachment $attachedFile) */ public function url($styleName) { - return $this->attachedFile->getInterpolator()->interpolate($this->attachedFile->url, $this->attachedFile, $styleName); + return $this->attachedFile->getInterpolator()->interpolate($this->attachedFile->url, $this->attachedFile, $styleName, true); } /**