#!/usr/bin/perl use strict; $|++; use My_HTML_Filter; ## from http://www.perlmonks.org/index.pl?node_id=29281 my %PERMITTED = map { my($k, @v) = split; ($k, {map {$_, 1} @v}) } split /\n/, <<'END'; a href name target class title b big blockquote class br center dd div class dl dt em font size color class h1 h2 h3 h4 h5 h6 hr i li ol type start p align class pre class small span class title strike strong sub sup table width cellpadding cellspacing border bgcolor class td width align valign colspan rowspan bgcolor height class th colspan width align bgcolor height class tr width align valign class tt class u ul END use Test::More qw(no_plan); my $f = My_HTML_Filter->new(\%PERMITTED) or die; isa_ok($f, "My_HTML_Filter"); is($f->strip(qq{Hello}), qq{

Hello

\n}, "basic text gets paragraphed"); is($f->strip(qq{

Thing}), qq{

Thing

\n}, "bogons gets stripped"); is($f->strip(qq{bar}), qq{bar\n}, "links are permitted"); is($f->strip(qq{bar}), qq{bar\n}, "attributes get quoted"); is($f->strip(qq{bar}), qq{bar\n}, "bad attributes get stripped"); is($f->strip(qq{

What do you say?}), qq{

What do you say?

\n}, "comments get stripped"); is($f->strip(qq{
Hi!}), qq{
Hi!
\n}, "tags get balanced"); is($f->strip(qq{bold italic!}), qq{bold italic!\n}, "b/i tags get balanced"); is($f->strip(qq{bold italic!}), qq{bold italic!\n}, "b/i tags get nested properly"); is($f->strip(qq{bold italic!}), qq{bold italic!\n}, "tags get lowercased"); is($f->strip(qq{

hey

one
two}), qq{

hey

\n

one
two

\n}, "br comes out as HTML not XHTML"); use Benchmark; my $homepage = do { open my $f, "homepage.html"; join "", <$f> }; timethese (-1, { strip_homepage => sub { $f->strip($homepage) } });