line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
package Templ::Filter::HTML; |
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
6
|
use Exporter; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
69
|
|
5
|
|
|
|
|
|
|
push @ISA, 'Exporter'; |
6
|
|
|
|
|
|
|
@EXPORT = qw(encode_html encode_entities uri_escape); |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
24
|
|
9
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
33
|
|
10
|
1
|
|
|
1
|
|
5
|
no warnings 'uninitialized'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
533
|
|
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
|
|
|
|
|
8
|
$str =~ s/</gs; |
22
|
5
|
|
|
|
|
8
|
$str =~ s/>/>/gs; |
23
|
5
|
|
|
|
|
86
|
return $str; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub uri_escape { |
27
|
2
|
|
|
2
|
0
|
3
|
my $str = shift; |
28
|
2
|
50
|
|
|
|
6
|
return '' unless defined $str; |
29
|
|
|
|
|
|
|
|
30
|
2
|
100
|
|
|
|
6
|
if ( not defined $url_regex ) { |
31
|
1
|
|
|
|
|
3
|
$url_regex = qr/[^A-Za-z0-9_\.~-]/; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
2
|
100
|
|
|
|
6
|
if ( not scalar keys %url_charmap ) { |
35
|
190
|
|
|
|
|
568
|
%url_charmap = map { chr($_) => sprintf( '%%%02X', $_ ); } |
36
|
1
|
|
|
|
|
4
|
grep { chr($_) =~ m/^$url_regex$/ } 0 .. 255; |
|
256
|
|
|
|
|
883
|
|
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
2
|
|
|
|
|
57
|
$str =~ s/($url_regex)/$url_charmap{$1}/gs; |
40
|
2
|
|
|
|
|
6
|
$str =~ s/\%20/+/gs; |
41
|
2
|
|
|
|
|
53
|
return $str; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub encode_entities { |
45
|
2
|
|
|
2
|
0
|
3
|
my $str = shift; |
46
|
2
|
50
|
|
|
|
6
|
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
|
|
|
|
|
8
|
$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
|
|
|
|
|
54
|
return $str; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
1; |