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
|
#!perl -w
use strict;
use Test::More tests => 9;
use HTML::Entities qw(_decode_entities);
eval {
_decode_entities("<", undef);
};
like($@, qr/^Can't inline decode readonly string/);
eval {
my $a = "";
_decode_entities($a, $a);
};
like($@, qr/^2nd argument must be hash reference/);
eval {
my $a = "";
_decode_entities($a, []);
};
like($@, qr/^2nd argument must be hash reference/);
$a = "<";
_decode_entities($a, undef);
is($a, "<");
_decode_entities($a, { "lt" => "<" });
is($a, "<");
my $x = "x" x 20;
my $err;
for (":", ":a", "a:", "a:a", "a:a:a", "a:::a") {
my $a = $_;
$a =~ s/:/&a;/g;
my $b = $_;
$b =~ s/:/$x/g;
_decode_entities($a, { "a" => $x });
if ($a ne $b) {
diag "Something went wrong with '$_'";
$err++;
}
}
ok(!$err);
$a = "foo bar";
_decode_entities($a, \%HTML::Entities::entity2char);
is($a, "foo\xA0bar");
$a = "foo bar";
_decode_entities($a, \%HTML::Entities::entity2char);
is($a, "foo bar");
_decode_entities($a, \%HTML::Entities::entity2char, 1);
is($a, "foo\xA0bar");
|