Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4.x]: null | purify throws a 500 server error #13495

Closed
maxfenton opened this issue Aug 2, 2023 · 3 comments
Closed

[4.x]: null | purify throws a 500 server error #13495

maxfenton opened this issue Aug 2, 2023 · 3 comments
Assignees

Comments

@maxfenton
Copy link

maxfenton commented Aug 2, 2023

What happened?

Description

Most of the time, I'm careful enough to check content before piping it to | purify like

{{ body ? tag('div', {
    class: 'rich-text text-size-body',
    html: body | purify('BodyCopy'),
}) }}

... but the following will cause a 500 Error on a site where devMode is false

{% set exampletext = somethingThatDoesNotExistOrIsEmpty ??? null %}
{{ exampletext | purify('BodyCopy') }}

and throw this error if devMode is true:

TypeError
craft\web\twig\Extension::purifyFilter(): Argument #1 ($html) must be of type string, null given, called in /var/www/site/production/shared/storage/runtime/compiled_templates/40/****.php on line 73

Steps to reproduce

  1. Run any null variable through the | purify filter

Expected behavior

I would expect a little more forgiveness from the | purify filter to return null if it receives null rather than TypeError what amounts to an empty $html parameter.

Actual behavior

TypeError above or 500 Error

Craft CMS version

4.4.16.1

PHP version

8.2.6

Operating system and version

Linux 5.15.0-1036-aws

Database type and version

MySQL 8.0.28

Image driver and version

Imagick 3.7.0 (ImageMagick 6.9.10-23)

Installed plugins and versions

No response

@i-just
Copy link
Contributor

i-just commented Aug 4, 2023

Hi, thanks for reporting! We’ve made the purify filter more forgiving. If a null value is provided to the $html parameter, it will return it immediately instead of throwing an error.

@maxfenton
Copy link
Author

Hi, thanks for reporting! We’ve made the purify filter more forgiving. If a null value is provided to the $html parameter, it will return it immediately instead of throwing an error.

Thank you so much!

I've recently made the switch from Redactor to CKeditor and (as part of that change) just started creating HTML Purifier configurations that match each CKeditor configuration.

@brandonkelly
Copy link
Member

Craft 4.4.17 is out with the purify change. Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants