Valiant/Filter/HtmlEscape.pm

filter: Statementstmt 100% 18 / 18 Branchbran 50.0% 1 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod 0.0% 0 / 2 totaltotal 88.4% 23 / 26 CC 2 SCAR 3.4
CC
2
Cov
95%
filter_each
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.4
« Valiant/Filter/Title.pm ↑ Summary Valiant/Filter/UcFirst.pm »
1 package Valiant::Filter::HtmlEscape;
2  
3 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Valiant::Util 'throw_exception';
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 with 'Valiant::Filter::Each';
7  
8 1 ▶sub normalize_shortcut {
Subroutine normalize_shortcut: called CC=1 SCAR=0.0
Pod undocumented
9 1 my ($class, $arg) = @_;
10 1 return +{ };
11 }
12  
13 1 ▶sub filter_each {
Subroutine filter_each: called CC=2 SCAR=7.0
Pod undocumented
14 1 my ($self, $class, $attrs, $attribute_name) = @_;
15 1 my $value = $attrs->{$attribute_name};
16 1 ▶ return unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 1 1
17  
18 1 $value =~ s/&(?!(amp|lt|gt|quot);)/&/g;
19 1 $value =~ s/</&lt;/g;
20 1 $value =~ s/>/&gt;/g;
21 1 $value =~ s/\"/&quot;/g;
22 1 return $value;
23 }
24  
25 1 1;
26  
27 =head1 NAME
28  
29 Valiant::Filter::HtmlEscape - HTML escaping on strings
30  
31 =head1 SYNOPSIS
32  
33 package Local::Test::User;
34  
35 use Moo;
36 use Valiant::Filters;
37  
38 has 'name' => (is=>'ro', required=>1);
39  
40 filters name => (
41 html_escape => 1,
42 );
43  
44  
45 my $user = Local::Test::User->new(name=>'<a>john</a>');
46  
47 print $user->name; # '&lt;a&gt;john&lt;/a&gt;'
48
49 =head1 DESCRIPTION
50  
51 This is a very simple filter that takes no paramters and HTML escapes any incoming
52 strings. Useful to help with stuff like cross scripting attacks, etc.
53  
54 Please be aware that the regexp for this might be too simple for truly hardening your code;
55 please review.
56  
57 =head1 SEE ALSO
58
59 L<Valiant>, L<Valiant::Filter>, L<Valiant::Validator::Filter>.
60  
61 =head1 AUTHOR
62
63 See L<Valiant>
64
65 =head1 COPYRIGHT & LICENSE
66
67 See L<Valiant>
68  
69 =cut
« Valiant/Filter/Title.pm ↑ Summary Valiant/Filter/UcFirst.pm »