line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
package Templ::Filter::HTML; |
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
4
|
use Exporter; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
77
|
|
5
|
|
|
|
|
|
|
push @ISA, 'Exporter'; |
6
|
|
|
|
|
|
|
@EXPORT = qw(encode_html encode_entities uri_escape); |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
24
|
|
9
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
36
|
|
10
|
1
|
|
|
1
|
|
5
|
no warnings 'uninitialized'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
528
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
my $url_regex; |
13
|
|
|
|
|
|
|
my %url_charmap; |
14
|
|
|
|
|
|
|
my %entity_cache; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub encode_html { |
17
|
5
|
|
|
5
|
0
|
155
|
my $str = shift; |
18
|
5
|
50
|
|
|
|
12
|
return '' unless defined $str; |
19
|
5
|
|
|
|
|
11
|
$str =~ s/&/&/gs; |
20
|
5
|
|
|
|
|
7
|
$str =~ s/"/"/gs; |
21
|
5
|
|
|
|
|
7
|
$str =~ s/</gs; |
22
|
5
|
|
|
|
|
9
|
$str =~ s/>/>/gs; |
23
|
5
|
|
|
|
|
83
|
return $str; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub uri_escape { |
27
|
2
|
|
|
2
|
0
|
4
|
my $str = shift; |
28
|
2
|
50
|
|
|
|
6
|
return '' unless defined $str; |
29
|
|
|
|
|
|
|
|
30
|
2
|
100
|
|
|
|
6
|
if ( not defined $url_regex ) { |
31
|
1
|
|
|
|
|
4
|
$url_regex = qr/[^A-Za-z0-9_\.~-]/; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
2
|
100
|
|
|
|
7
|
if ( not scalar keys %url_charmap ) { |
35
|
190
|
|
|
|
|
558
|
%url_charmap = map { chr($_) => sprintf( '%%%02X', $_ ); } |
36
|
1
|
|
|
|
|
3
|
grep { chr($_) =~ m/^$url_regex$/ } 0 .. 255; |
|
256
|
|
|
|
|
935
|
|
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
2
|
|
|
|
|
55
|
$str =~ s/($url_regex)/$url_charmap{$1}/gs; |
40
|
2
|
|
|
|
|
7
|
$str =~ s/\%20/+/gs; |
41
|
2
|
|
|
|
|
51
|
return $str; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub encode_entities { |
45
|
2
|
|
|
2
|
0
|
3
|
my $str = shift; |
46
|
2
|
50
|
|
|
|
7
|
return '' unless defined $str; |
47
|
|
|
|
|
|
|
|
48
|
2
|
100
|
|
|
|
6
|
if ( not scalar keys %entity_cache ) { |
49
|
1
|
|
|
|
|
4
|
%entity_cache = ( |
50
|
|
|
|
|
|
|
'&' => '&', |
51
|
|
|
|
|
|
|
'"' => '"', |
52
|
|
|
|
|
|
|
'<' => '<', |
53
|
|
|
|
|
|
|
'>' => '>', |
54
|
|
|
|
|
|
|
); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
2
|
|
|
|
|
9
|
$str =~ s/([^\ \!\#\$\%\x28-\x3B\=\x3F-\x7E])/ |
58
|
2
|
|
|
|
|
5
|
my $out = $entity_cache{$1}; |
59
|
2
|
100
|
|
|
|
6
|
unless (defined $out) |
60
|
|
|
|
|
|
|
{ |
61
|
1
|
|
|
|
|
4
|
$out = sprintf '%X;', ord($1); |
62
|
1
|
|
|
|
|
3
|
$entity_cache{$1} = $out; |
63
|
|
|
|
|
|
|
} |
64
|
2
|
|
|
|
|
5
|
$out; |
65
|
|
|
|
|
|
|
/egsx; |
66
|
2
|
|
|
|
|
49
|
return $str; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
1; |