File: 40bodytext.t

package info (click to toggle)
libhtml-stripscripts-perl 1.06-1%2Bdeb11u1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 492 kB
  • sloc: perl: 1,004; makefile: 2
file content (95 lines) | stat: -rw-r--r-- 2,613 bytes parent folder | download | duplicates (5)
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 (
      ['<','&lt;'],
      ['>','&gt;'],
      ['&','&amp;'],
      ['"','&quot;'],
      ["'",'&#39;'],
      ['a','a'],
    ) {
        my ($in, $out) = @$pair;

        push @tests, [ $in, $out ];
        push @tests, [ $out, $out ];

        my $dec = ord $in;
        push @tests, [ "&#$dec;", $out ];
        push @tests, [ "&#0$dec;", $out ];
        push @tests, [ "&#000$dec;", $out ];

        my $hex = sprintf '%x', $dec;
        push @tests, [ "&#x$hex;", $out ];
        push @tests, [ "&#X$hex;", $out ];
        push @tests, [ "&#x0$hex;", $out ];
        push @tests, [ "&#X0$hex;", $out ];
        push @tests, [ "&#x000$hex;", $out ];
        push @tests, [ "&#X000$hex;", $out ];

        if ($hex =~ /[a-f]/) {
            $hex = uc $hex;
            push @tests, [ "&#x$hex;", $out ];
            push @tests, [ "&#X$hex;", $out ];
            push @tests, [ "&#x0$hex;", $out ];
            push @tests, [ "&#X0$hex;", $out ];
            push @tests, [ "&#x000$hex;", $out ];
            push @tests, [ "&#X000$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/"/&quot;/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=]" );
}