From 8ba03b3f20418562f624570f71536b35ffe18517 Mon Sep 17 00:00:00 2001 From: Bastien70 Date: Wed, 12 Jan 2022 17:06:37 +0100 Subject: [PATCH 1/2] Allow null value for sanitize filter --- src/Twig/TwigExtension.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Twig/TwigExtension.php b/src/Twig/TwigExtension.php index e6d5deb..8bb7997 100644 --- a/src/Twig/TwigExtension.php +++ b/src/Twig/TwigExtension.php @@ -36,8 +36,8 @@ public function getFilters(): array ]; } - public function sanitize(string $html, string $sanitizer = null): string + public function sanitize(?string $html = null, string $sanitizer = null): string { - return $this->sanitizers->get($sanitizer ?: $this->default)->sanitize($html); + return $html ?: $this->sanitizers->get($sanitizer ?: $this->default)->sanitize($html); } } From 99db8b7bc44d92e026d46e42d84bb82a435956e7 Mon Sep 17 00:00:00 2001 From: Bastien70 Date: Thu, 13 Jan 2022 09:16:02 +0100 Subject: [PATCH 2/2] Fix error --- src/Twig/TwigExtension.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Twig/TwigExtension.php b/src/Twig/TwigExtension.php index 8bb7997..b6ed2b3 100644 --- a/src/Twig/TwigExtension.php +++ b/src/Twig/TwigExtension.php @@ -36,8 +36,8 @@ public function getFilters(): array ]; } - public function sanitize(?string $html = null, string $sanitizer = null): string + public function sanitize(?string $html = null, string $sanitizer = null): ?string { - return $html ?: $this->sanitizers->get($sanitizer ?: $this->default)->sanitize($html); + return $html ? $this->sanitizers->get($sanitizer ?: $this->default)->sanitize($html) : null; } }