File: scheme.t

package info (click to toggle)
libhtml-restrict-perl 3.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 364 kB
  • sloc: perl: 842; makefile: 7
file content (70 lines) | stat: -rw-r--r-- 1,565 bytes parent folder | download | duplicates (2)
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
use strict;
use warnings;

use Test::More;
use HTML::Restrict ();

my $hr = HTML::Restrict->new(
    rules => {
        a          => [qw( href )],
        img        => [qw( src /)],
        blockquote => [qw( cite )],
    },
);

$hr->set_uri_schemes( [ 'http', 'https', undef, 'ftp' ] );

cmp_ok(
    $hr->process(q{<a href="http://example.com">link</a>}),
    'eq', q{<a href="http://example.com">link</a>},
    'http scheme preserved',
);

cmp_ok(
    $hr->process(q{<a href="https://example.com">link</a>}),
    'eq', q{<a href="https://example.com">link</a>},
    'https scheme preserved',
);

cmp_ok(
    $hr->process(q{<a href="/some/file">link</a>}),
    'eq', q{<a href="/some/file">link</a>},
    'relative scheme preserved',
);

cmp_ok(
    $hr->process(q{<a href="ftp://example.com">link</a>}),
    'eq', q{<a href="ftp://example.com">link</a>},
    'ftp scheme preserved',
);

cmp_ok(
    $hr->process(q{<a href="file://example.com">link</a>}),
    'eq', '<a>link</a>',
    'file scheme removed',
);

cmp_ok(
    $hr->process(q{<img src="javascript:evil_fc()" />}),
    'eq', '<img>',
    'img src with javascript removed',
);

cmp_ok(
    $hr->process(
        q{<blockquote cite="javascript:evil_fc()">blockquote</blockquote>}),
    'eq',
    '<blockquote>blockquote</blockquote>',
    'blockquote cite with javascript removed',
);

# disable relative schemes
$hr->set_uri_schemes( [ 'http', 'https', 'ftp' ] );

cmp_ok(
    $hr->process(q{<a href="/some/file">link</a>}),
    'eq', '<a>link</a>',
    'relative scheme removed',
);

done_testing();