Exercise / HTMLPurifierBundle

HTML Purifier is a standards-compliant HTML filter library written in PHP.
http://htmlpurifier.org/
Other
275 stars 56 forks source link

Improved Form Listener #65

Closed markitosgv closed 3 years ago

markitosgv commented 5 years ago

When you try to get purified some array elements, default listener doesn't work.

I override listener to do something like this:

    public function purifySubmittedData(FormEvent $event)
    {
        $event->setData($this->purifyResult($event->getData()));
    }

    protected function purifyResult($data)
    {
        if (\is_array($data)) {
            array_walk($data, function (&$item) {
                $item = $this->purifyResult($item);
            });
        }

        if (\is_string($data)) {
            return $this->getPurifier()->purify($data);
        }

        return $data;
    }

What do you think about this?

HeahDude commented 4 years ago

Hello @makasim, could you explain what is the use case? Because actually the listener is used for a TextType extension, which should not have to deal with non scalar values.

This usage has also been constrained is Symfony core for security reasons. Only compound forms should deal with array values (some exceptions exist in core for file and select input that can be multiple but they do handle trim differently though).

Then for compound forms each inner field is responsible for trimming its own value.

I would prefer to be sure the use case is common enough before implementing a solution like the one you proposed. Thanks!

HeahDude commented 3 years ago

Closing here for lack of feedback. Don't hesitate to reopen if needed, thanks!