From 858f83aff56a6cdd36747b010116be12da6a4cfb Mon Sep 17 00:00:00 2001 From: martijnve Date: Fri, 5 Apr 2019 10:47:19 +0200 Subject: [PATCH] Fix allow data uri on img (#27) * Fix allow_data_uri on img tag breaking regular url When allow_data_uri is set to true and allowed_hosts is kept at null the latter is converted to [null] which disallows all urls * Dont override current list of allowedHosts --- src/Extension/Image/Sanitizer/ImgSrcSanitizer.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Extension/Image/Sanitizer/ImgSrcSanitizer.php b/src/Extension/Image/Sanitizer/ImgSrcSanitizer.php index 6fd1a88..708e364 100644 --- a/src/Extension/Image/Sanitizer/ImgSrcSanitizer.php +++ b/src/Extension/Image/Sanitizer/ImgSrcSanitizer.php @@ -38,7 +38,9 @@ public function sanitize(?string $input): ?string if ($this->allowDataUri) { $allowedSchemes[] = 'data'; - $allowedHosts[] = null; + if (null !== $allowedHosts) { + $allowedHosts[] = null; + } } if (!$sanitized = $this->sanitizeUrl($input, $allowedSchemes, $allowedHosts, $this->forceHttps)) {