diff --git a/MANIFEST b/MANIFEST index 05050e2..d6f14bc 100644 --- a/MANIFEST +++ b/MANIFEST @@ -18,5 +18,6 @@ t/09-callbacks.t t/10-uri.t t/11-rebase.t t/12-ruleset.t +t/13-minimal.t t/pod-coverage.t t/pod.t diff --git a/lib/HTML/Laundry/Rules/Minimal.pm b/lib/HTML/Laundry/Rules/Minimal.pm index e6b17b8..941b5ce 100644 --- a/lib/HTML/Laundry/Rules/Minimal.pm +++ b/lib/HTML/Laundry/Rules/Minimal.pm @@ -22,7 +22,7 @@ a, b, blockquote, code, em, i, li, ol, p, pre, strong, u, and ul sub acceptable_e { my $self = shift; my @acceptable = qw( - a b blockquote code em i li ol p pre strong u ul + a b br blockquote code em i li ol p pre strong u ul ); my %acceptable = map { ( $_, 1 ) } @acceptable; return \%acceptable; diff --git a/t/12-ruleset.t b/t/12-ruleset.t index 05aef03..8457ff3 100644 --- a/t/12-ruleset.t +++ b/t/12-ruleset.t @@ -43,5 +43,4 @@ is( $l7->clean( $str ), $str, my $l8 = HTML::Laundry->new({}); ok( $l8, 'Created Laundry object with no argument' ); is( $l8->clean( $str ), $str, - 'Ruleset defaults to HTML::Laundry::Rules::Default' ); - \ No newline at end of file + 'Ruleset defaults to HTML::Laundry::Rules::Default' ); \ No newline at end of file diff --git a/t/13-minimal.t b/t/13-minimal.t new file mode 100644 index 0000000..effd8d3 --- /dev/null +++ b/t/13-minimal.t @@ -0,0 +1,71 @@ +use strict; +use warnings; + +use Test::More tests => 158; + +require_ok('HTML::Laundry'); +require_ok('HTML::Laundry::Rules::Minimal'); + +my $l1 = HTML::Laundry->new({ notidy => 1, + rules => 'HTML::Laundry::Rules::Minimal' }); + +my @ok = qw( a b br blockquote code em i li ol p pre strong u ul ); +my %ok = map { $_ => 1 } @ok; + +my @e = ( + 'a', 'abbr', 'acronym', 'address', 'area', 'b', 'bdo', 'big', 'blockquote', + 'br', 'button', 'caption', 'center', 'cite', 'code', 'col', 'colgroup', 'dd', + 'del', 'dfn', 'dir', 'div', 'dl', 'dt', 'em', 'fieldset', 'font', 'form', + 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'hr', 'i', 'img', 'input', 'ins', 'kbd', + 'label', 'legend', 'li', 'map', 'menu', 'ol', 'optgroup', 'option', 'p', + 'pre', 'q', 's', 'samp', 'select', 'small', 'span', 'strike', 'strong', + 'sub', 'sup', 'table', 'tbody', 'td', 'textarea', 'tfoot', 'th', 'thead', + 'tr', 'tt', 'u', 'ul', 'var', 'wbr' +); + +foreach my $e ( @e ) { + if ( $ok{$e} and $e ne 'br' ) { + # The only allowed empty element in this ruleset is
+ is( $l1->clean("<$e>"), "<$e>", "element $e is not sanitized"); + } elsif ( $ok{$e} ) { + is( $l1->clean("<$e>"), "<$e />", "element $e is not sanitized"); + } else { + is( $l1->clean("<$e>"), "", "element $e is sanitized"); + } +} + +my @a = ( 'abbr', 'accept', 'accept-charset', 'accesskey', 'action', 'align', 'alt', + 'axis', 'border', 'cellpadding', 'cellspacing', 'char', 'charoff', 'charset', + 'checked', 'cite', 'class', 'clear', 'color', 'cols', 'colspan', 'compact', + 'coords', 'datetime', 'dir', 'disabled', 'enctype', 'for', 'frame', + 'headers', 'height', 'href', 'hreflang', 'hspace', 'id', 'ismap', 'label', + 'lang', 'longdesc', 'maxlength', 'media', 'method', 'multiple', 'name', + 'nohref', 'noshade', 'nowrap', 'prompt', 'readonly', 'rel', 'rev', 'rows', + 'rowspan', 'rules', 'scope', 'selected', 'shape', 'size', 'span', 'src', + 'start', 'summary', 'tabindex', 'target', 'title', 'type', 'usemap', + 'valign', 'value', 'vspace', 'width', 'xml:lang' ); + +ok( ! $l1->clean(''), '