1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
|
use strict;
use vars qw(@tests);
BEGIN {
$^W = 1;
@tests = (
[ '', '' ],
[ ''', ''' ],
[ '&', '&' ],
[ '&', '&' ],
[ '&*', '&*' ],
[ '穩', '穩' ],
[ 'ő', 'ő' ],
[ '', '' ],
[ '', '' ],
[ '', '' ],
[ '', '' ],
[ '&foo;', '&foo;' ],
[ '&Foo3;', '&Foo3;' ],
[ "\0", ' ' ],
);
foreach my $pair (
['<','<'],
['>','>'],
['&','&'],
['"','"'],
["'",'''],
['a','a'],
) {
my ($in, $out) = @$pair;
push @tests, [ $in, $out ];
push @tests, [ $out, $out ];
my $dec = ord $in;
push @tests, [ "&#$dec;", $out ];
push @tests, [ "�$dec;", $out ];
push @tests, [ "�$dec;", $out ];
my $hex = sprintf '%x', $dec;
push @tests, [ "&#x$hex;", $out ];
push @tests, [ "&#X$hex;", $out ];
push @tests, [ "�$hex;", $out ];
push @tests, [ "�$hex;", $out ];
push @tests, [ "�$hex;", $out ];
push @tests, [ "�$hex;", $out ];
if ($hex =~ /[a-f]/) {
$hex = uc $hex;
push @tests, [ "&#x$hex;", $out ];
push @tests, [ "&#X$hex;", $out ];
push @tests, [ "�$hex;", $out ];
push @tests, [ "�$hex;", $out ];
push @tests, [ "�$hex;", $out ];
push @tests, [ "�$hex;", $out ];
}
}
}
use Test::More tests => 4 * scalar(@tests);
use HTML::StripScripts;
my $f = HTML::StripScripts->new;
foreach my $test (@tests) {
my ($in, $out) = @$test;
$f->input_start_document;
$f->input_text($in);
$f->input_end_document;
is( $f->filtered_document, $out, "text input [$in]" );
$f->input_start_document;
$f->input_text("=$in=");
$f->input_end_document;
is( $f->filtered_document, "=$out=", "text input [=$in=]" );
my $esc = $in;
$esc =~ s/"/"/g;
$f->input_start_document;
$f->input_start(qq{<img alt="$esc">});
$f->input_end_document;
is( $f->filtered_document, qq{<img alt="$out" />}, "img alt input [$in]" );
$f->input_start_document;
$f->input_start(qq{<img alt="=$esc=">});
$f->input_end_document;
is( $f->filtered_document, qq{<img alt="=$out=" />}, "img alt input [=$in=]" );
}
|