From 333aff326b11afc0a04ecfb3cb386bdcb3074958 Mon Sep 17 00:00:00 2001 From: Bob van de Vijver Date: Wed, 16 Sep 2020 10:11:21 +0200 Subject: [PATCH 1/2] #76: Allow null input in Twig extension --- src/Twig/HTMLPurifierRuntime.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Twig/HTMLPurifierRuntime.php b/src/Twig/HTMLPurifierRuntime.php index 8c152528..46e098d5 100644 --- a/src/Twig/HTMLPurifierRuntime.php +++ b/src/Twig/HTMLPurifierRuntime.php @@ -17,13 +17,17 @@ public function __construct(HTMLPurifiersRegistryInterface $registry) /** * Filters the input through an \HTMLPurifier service. * - * @param string $string The html string to purify + * @param string|null $string The html string to purify * @param string $profile A configuration profile name * * @return string The purified html string */ - public function purify(string $string, string $profile = 'default'): string + public function purify(?string $string, string $profile = 'default'): string { + if (null === $string) { + return ''; + } + return $this->getHTMLPurifierForProfile($profile)->purify($string); } From 412fa43155cf9041beee85cbbc585cd3581bab9e Mon Sep 17 00:00:00 2001 From: Bob van de Vijver Date: Wed, 16 Sep 2020 12:58:14 +0200 Subject: [PATCH 2/2] Fix CS --- src/Twig/HTMLPurifierRuntime.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Twig/HTMLPurifierRuntime.php b/src/Twig/HTMLPurifierRuntime.php index 46e098d5..f1ba5df4 100644 --- a/src/Twig/HTMLPurifierRuntime.php +++ b/src/Twig/HTMLPurifierRuntime.php @@ -18,7 +18,7 @@ public function __construct(HTMLPurifiersRegistryInterface $registry) * Filters the input through an \HTMLPurifier service. * * @param string|null $string The html string to purify - * @param string $profile A configuration profile name + * @param string $profile A configuration profile name * * @return string The purified html string */ @@ -27,7 +27,7 @@ public function purify(?string $string, string $profile = 'default'): string if (null === $string) { return ''; } - + return $this->getHTMLPurifierForProfile($profile)->purify($string); }