in reply to Stopping the abuse
my (blush) HTML::TagFilter is written with this in mind. it's just a subclass of HTML::Parser, and as always there are many other ways to do it. Many here would probably recommend building a screen of your own on HTML::TokeParser. Ymmv.
TagFilter is very young (0.08 or so), and pulls in quite a lot of cpan with it (all the cleverness is in the Parser), but it's meant to be very easy to use. to eliminate all html from input, you would just need to do this:
use HTML::TagFilter; my $dirty_text = ...; #something from input my $tf = HTML::TagFilter->new(); $tf->allow_tags(); my $clean_text = $tf->filter($dirty_text);
and to allow formatting html but disallow images and links (and strip out javascript from other tags):
use HTML::TagFilter; my $dirty_text = ...; #something from input my $tf = HTML::TagFilter->new(); $tf->deny_tags({ img=> {all => []}, a => {all => []}, }); my $clean_text = $tf->filter($dirty_text);
(images and links are let through by default, so a couple of rules must be added to eliminate them).
and so on. but getting this right requires a lot of attention to browser behaviour. it's amazing what range of things explorer will interpret as an instruction, for example, and i'm always trying to keep up. best to be very restrictive to begin with and only relax the restrictions with great care.
ps. new version soon, honest.
|
|---|