blib/lib/HTML/StripTags.pm

filter: Statementstmt 78.6% 184 / 234 Branchbran 83.6% 102 / 122 Conditioncond 56.2% 54 / 96 MC/DCmcdc 32.6% 16 / 49 Subroutinesub 100% 6 / 6 Podpod 100% 1 / 1 totaltotal 71.4% 363 / 508 CC 94 SCAR 54.6
CC
94
Cov
75%
strip_tags
246.9
BEGIN
1.0
BEGIN
1.0
CRAP 234.5
↑ Summary
1 package HTML::StripTags;
2  
3 =head1 NAME
4  
5 HTML::StripTags - Strip HTML or XML tags from a string with Perl like PHP's strip_tags() does
6  
7 =head1 SYNOPSIS
8  
9 use HTML::StripTags qw(strip_tags);
10  
11 $string = '<html>Hallo <u>beautiful</u> <a href="http://worldonline.com">world</a>!</html>';
12 $allowed_tags = '<u><b>';
13  
14 print strip_tags( $string, $allowed_tags );
15  
16 =head1 DESCRIPTION
17  
18 HTML::StripTags provides the function strip_tags() that can strip all HTML or XML tags from a string except the given allowed tags.
19 This is a Perl port of the PHP function strip_tags() based on PHP 5.3.3.
20  
21 =head1 SECURITY NOTE
22  
23 Please note: As per L<http://htmlpurifier.org/comparison#striptags> PHP's strip_tags() is a very basic and unsafe method, so it's strongly recommended not to use it for cleaning up user input!
24 As HTML::StripTags uses the same state machine, the same applies to this module.
25  
26 =head1 METHODS
27  
28 =cut
29  
30 #------------------------- Pragmas ---------------------------------------------
31 15 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 15 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
33  
34 #------------------------- Libs ------------------------------------------------
35 15 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
36 15 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
37 15 ▶use Switch 'fallthrough';
Subroutine BEGIN: called CC=1 SCAR=0.0
38  
39 15 our $VERSION = '1.01';
40 15 our @ISA = qw(Exporter);
41 15 our @EXPORT_OK = qw(strip_tags);
42  
43 =head2 strip_tags()
44  
45 A simple little state-machine to strip out html and php tags
46  
47 State 0 is the output state, state 1 means we are inside a
48 normal html tag, state 2 means we are inside a php tag, state 3
49 means we are inside a "<!--", case 4 means we are inside the
50 following JavaScript/CSS/etc. tag.
51  
52 When an allow string is passed in we keep track of the string
53 in state 1 and when the tag is closed check it against the
54 allow string to see if we should allow it.
55  
56 print strip_tags( $string, "<u><b><?php<?" );
57  
58 print strip_tags( $string, ('<u>', '<b>', '<?php', '<?') );
59  
60 =cut
61  
62 161 ▶sub strip_tags {
Subroutine strip_tags: called CC=94 SCAR=55.1
Pod documented
63 161 my ( $string, $allow ) = @_;
64  
65 161 ▶ if (scalar(@_) == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ == 0) 1 160 161
66 1 croak sprintf "strip_tags() expects at least 1 parameter, %d given", scalar(@_);
67 0 return;
68 }
69 160 ▶ if (scalar(@_) > 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ > 2) 1 159 160
70 1 croak sprintf "strip_tags() expects at most 2 parameters, %d given", scalar(@_);
71 0 return;
72 }
73 159 ▶ if (ref($string) ne 'STRING' && ref($string) ne '') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $string ne "STRING" and ref $string ne "") 21 138 159
Condition66%2/3
ref $string ne "STRING" and ref $string ne ""
!ll&&!rl&&r
013821
MC/DC50%1/2
ref $string ne "STRING" and ref $string ne ""
ref $string ne "STRING" ref $string ne ""
Truth table66%2/3
A and B
A= ref $string ne "STRING"B= ref $string ne ""
ABresult
0X0
100
111
74 21 croak sprintf "strip_tags() expects parameter 1 to be string, %s given", ref($string);
75 0 return;
76 }
77 138 ▶ if (ref($allow) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $allow eq "ARRAY") 4 134 138
78 4 $allow = join "", @$allow;
79 4 croak "Array to string conversion";
80 }
81  
82 134 my $i = 0; # while counter
83 134 ▶ my $len = defined $string ? length($string) : 0; # while end condition
Branch: 1 branch
BranchTrueFalseTotal
defined $string ? : 130 4 134
84 134 ▶ my @buf = defined $string ? split(//, $string) : (); # input buffer
Branch: 1 branch
BranchTrueFalseTotal
defined $string ? : 130 4 134
85 134 my @tbuf = (); # tag buffer
86 134 my @rbuf = (); # return buffer
87 134 my $c = $buf[0]; # current character of buf
88 134 my $p = 0; # current position of c in buf
89 134 my $lc = "\0"; # holds the last significant character read
90 134 my $br = 0; # bracket counter
91 134 my $depth = 0; # tag depth
92 134 my $in_q = 0; # in quote
93 134 my $state = 0; # State 0 is the output state, state 1 means we are inside a
94 # normal html tag, state 2 means we are inside a php tag, state 3
95 # means we are inside a "<!--", case 4 means we are inside the
96 # following JavaScript/CSS/etc. tag.
97  
98 134 ▶ if ($allow) {
Branch: 1 branch
BranchTrueFalseTotal
if ($allow) 82 52 134
99 82 $allow = lc($allow);
100 }
101  
102 134 ▶ while ($i < $len) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $len) 5620 134 5754
103 5620 switch ($c) {
104 5620 ▶ case "\0" {
Branch: 1 branch
BranchTrueFalseTotal
if (&Switch::case("\0")) 4 5616 5620
105 4 last;
106 0 }
107 5616 ▶ case '<' {
Branch: 1 branch
BranchTrueFalseTotal
if (&Switch::case("<")) 438 5178 5616
108 438 ▶ if ($in_q) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in_q) 3 435 438
109 3 last;
110 }
111 435 ▶ if ($buf[$p + 1] =~ /\s/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($buf[$p + 1] =~ /\s/) 3 432 435
112 3 next;
113 }
114 432 ▶ if ($state == 0) {
Branch: 2 branches
BranchTrueFalseTotal
if ($state == 0) { } 420 12 432
elsif ($state == 1) { } 8 4 12
115 420 $lc = '<';
116 420 $state = 1;
117 420 ▶ if ($allow) {
Branch: 1 branch
BranchTrueFalseTotal
if ($allow) 329 91 420
118 329 push @tbuf, '<';
119 }
120 } elsif ($state == 1) {
121 8 $depth++;
122 }
123 432 last;
124 3 }
125 5181 ▶ case '(' {
Branch: 1 branch
BranchTrueFalseTotal
if (&Switch::case("(")) 4 5177 5181
126 4 ▶ if ($state == 2) {
Branch: 3 branches
BranchTrueFalseTotal
if ($state == 2) { } 0 4 4
elsif ($allow and $state == 1) { } 0 4 4
elsif ($state == 0) { } 4 0 4
127 0 ▶ if ($lc ne '"' && $lc ne "'") {
Branch: 1 branch
BranchTrueFalseTotal
if ($lc ne "\"" and $lc ne "'") 0 0 0
Condition0%0/3
$lc ne "\"" and $lc ne "'"
!ll&&!rl&&r
000
MC/DC0%0/2
$lc ne "\"" and $lc ne "'"
$lc ne "\"" $lc ne "'"
Truth table0%0/3
A and B
A= $lc ne "\""B= $lc ne "'"
ABresult
0X0
100
111
128 0 $lc = '(';
129 0 $br++;
130 }
131 ▶ } elsif ($allow && $state == 1) {
Condition33%1/3
$allow and $state == 1
!ll&&!rl&&r
040
MC/DC0%0/2
$allow and $state == 1
$allow $state == 1
Truth table33%1/3
A and B
A= $allowB= $state == 1
ABresult
0X0
100
111
132 0 push @rbuf, $c;
133 } elsif ($state == 0) {
134 4 push @rbuf, $c;
135 }
136 4 last;
137 0 }
138 5177 ▶ case ')' {
Branch: 1 branch
BranchTrueFalseTotal
if (&Switch::case(")")) 4 5173 5177
139 4 ▶ if ($state == 2) {
Branch: 3 branches
BranchTrueFalseTotal
if ($state == 2) { } 0 4 4
elsif ($allow and $state == 1) { } 0 4 4
elsif ($state == 0) { } 4 0 4
140 0 ▶ if ($lc ne '"' && $lc ne "'") {
Branch: 1 branch
BranchTrueFalseTotal
if ($lc ne "\"" and $lc ne "'") 0 0 0
Condition0%0/3
$lc ne "\"" and $lc ne "'"
!ll&&!rl&&r
000
MC/DC0%0/2
$lc ne "\"" and $lc ne "'"
$lc ne "\"" $lc ne "'"
Truth table0%0/3
A and B
A= $lc ne "\""B= $lc ne "'"
ABresult
0X0
100
111
141 0 $lc = ')';
142 0 $br--;
143 }
144 ▶ } elsif ($allow && $state == 1) {
Condition33%1/3
$allow and $state == 1
!ll&&!rl&&r
040
MC/DC0%0/2
$allow and $state == 1
$allow $state == 1
Truth table33%1/3
A and B
A= $allowB= $state == 1
ABresult
0X0
100
111
145 0 push @rbuf, $c;
146 } elsif ($state == 0) {
147 4 push @rbuf, $c;
148 }
149 4 last;
150 0 }
151 5173 ▶ case '>' {
Branch: 1 branch
BranchTrueFalseTotal
if (&Switch::case(">")) 440 4733 5173
152 440 ▶ if ($depth) {
Branch: 1 branch
BranchTrueFalseTotal
if ($depth) 8 432 440
153 8 $depth--;
154 8 last;
155 }
156  
157 432 ▶ if ($in_q) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in_q) 3 429 432
158 3 last;
159 }
160  
161 429 switch ($state) {
162 429 ▶ case 1 { # HTML/XML
Branch: 1 branch
BranchTrueFalseTotal
if (&Switch::case(1)) 344 85 429
163 344 $lc = '>';
164 344 $in_q = $state = 0;
165 344 ▶ if ($allow) {
Branch: 1 branch
BranchTrueFalseTotal
if ($allow) 278 66 344
166 278 push @tbuf, '>';
167 278 ▶ if ($allow =~ (join '', ((join '', map(lc, @tbuf)) =~ m!(<)/?(\S+)(?:.*)(>)! ))) {
Branch: 1 branch
BranchTrueFalseTotal
if ($allow =~ join("", join("", map(lc($_), @tbuf)) =~ m[(<)/?(\S+)(?:.*)(>)])) 72 206 278
168 72 push @rbuf, @tbuf;
169 }
170 278 @tbuf = ();
171 }
172 344 last;
173 0 }
174 85 ▶ case 2 { # PHP
Branch: 1 branch
BranchTrueFalseTotal
if (&Switch::case(2)) 58 27 85
175 58 ▶ if (!$br && $lc ne '"' && $buf[$p-1] eq '?') {
Branch: 1 branch
BranchTrueFalseTotal
if (not $br and $lc ne "\"" and $buf[$p - 1] eq "?") 53 5 58
Condition50%3/6
not $br and $lc ne "\"" and $buf[$p - 1] eq "?"
!ll&&!rl&&r
0553
not $br and $lc ne "\""
!ll&&!rl&&r
0058
MC/DC33%1/3
not $br and $lc ne "\"" and $buf[$p - 1] eq "?"
not $br $lc ne "\"" $buf[$p - 1] eq "?"
Truth table50%2/4
not(A) and B and C
A= not $brB= $lc ne "\""C= $buf[$p - 1] eq "?"
ABCresult
0XX0
10X0
1100
1111
176 53 $in_q = $state = 0;
177 53 @tbuf = ();
178 }
179 58 last;
180 0 }
181 0 ▶ case 3 { # <!--
Branch: 1 branch
BranchTrueFalseTotal
if (&Switch::case(3)) 0 27 27
182 0 $in_q = $state = 0;
183 0 @tbuf = ();
184 0 last;
185 0 }
186 27 ▶ case 4 { # Inside <!-- comment -->
Branch: 1 branch
BranchTrueFalseTotal
if (&Switch::case(4)) 24 3 27
187 24 ▶ if ($p >= 2 && $buf[$p-1] eq '-' && $buf[$p-2] eq '-') {
Branch: 1 branch
BranchTrueFalseTotal
if ($p >= 2 and $buf[$p - 1] eq "-" and $buf[$p - 2] eq "-") 23 1 24
Condition66%4/6
$p >= 2 and $buf[$p - 1] eq "-" and $buf[$p - 2] eq "-"
!ll&&!rl&&r
1023
$p >= 2 and $buf[$p - 1] eq "-"
!ll&&!rl&&r
0123
MC/DC33%1/3
$p >= 2 and $buf[$p - 1] eq "-" and $buf[$p - 2] eq "-"
$p >= 2 $buf[$p - 1] eq "-" $buf[$p - 2] eq "-"
Truth table50%2/4
A and B and C
A= $p >= 2B= $buf[$p - 1] eq "-"C= $buf[$p - 2] eq "-"
ABCresult
0XX0
10X0
1100
1111
188 23 $in_q = $state = 0;
189 23 @tbuf = ();
190 }
191 24 last;
192 0 }
193 3 ▶ case qr/\d/ {
Branch: 1 branch
BranchTrueFalseTotal
if (&Switch::case(qr/\d/)) 3 0 3
194 3 push @rbuf, $c;
195 3 last;
196 0 }
197 0 }
198 429 last;
199 0 }
200 4733 ▶ case m/\'|\"/ {
Branch: 1 branch
BranchTrueFalseTotal
if (&Switch::case(qr/\'|\"/)) 45 4688 4733
201 45 ▶ if ($state == 4) {
Branch: 4 branches
BranchTrueFalseTotal
if ($state == 4) { } 0 45 45
elsif ($state == 2 and $buf[$p - 1] ne '\\') { } 2 43 45
elsif ($state == 0) { } 9 34 43
elsif ($allow and $state == 1) { } 18 32 50
202 # Inside <!-- comment -->
203 0 last;
204 ▶ } elsif (($state == 2) && $buf[$p-1] ne '\\') {
Condition100%3/3
$state == 2 and $buf[$p - 1] ne "\\"
!ll&&!rl&&r
3942
MC/DC100%2/2
$state == 2 and $buf[$p - 1] ne "\\"
$state == 2 $buf[$p - 1] ne "\\"
Truth table100%3/3
A and B
A= $state == 2B= $buf[$p - 1] ne "\\"
ABresult
0X0
100
111
205 # Inside PHP
206 2 ▶ if ($lc eq $c) {
Branch: 2 branches
BranchTrueFalseTotal
if ($lc eq $c) { } 1 1 2
elsif ($lc ne '\\') { } 1 0 1
207 1 $lc = "\0";
208 } elsif ($lc ne '\\') {
209 1 $lc = $c;
210 }
211 } elsif ($state == 0) {
212 # Outside a tag
213 9 push @rbuf, $c;
214 ▶ } elsif ($allow && $state == 1) {
Condition66%2/3
$allow and $state == 1
!ll&&!rl&&r
16018
MC/DC50%1/2
$allow and $state == 1
$allow $state == 1
Truth table66%2/3
A and B
A= $allowB= $state == 1
ABresult
0X0
100
111
215 # Inside a tag
216 18 push @tbuf, $c;
217 }
218 45 ▶ if ($state && $p != 0 && ($state == 1 || $buf[$p-1] ne '\\') && (!$in_q || $buf[$p] eq $in_q)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($state and $p != 0 and $state == 1 || $buf[$p - 1] ne "\\" and !$in_q || $buf[$p] eq $in_q) 32 13 45
Condition80%12/15
$state and $p != 0 and $state == 1 || $buf[$p - 1] ne "\\" and !$in_q || $buf[$p] eq $in_q
!ll&&!rl&&r
13032
$state and $p != 0 and $state == 1 || $buf[$p - 1] ne "\\"
!ll&&!rl&&r
9432
$state and $p != 0
!ll&&!rl&&r
9036
$state == 1 or $buf[$p - 1] ne "\\"
l!l&&r!l&&!r
3024
not $in_q or $buf[$p] eq $in_q
l!l&&r!l&&!r
16160
MC/DC50%3/6
$state and $p != 0 and $state == 1 || $buf[$p - 1] ne "\\" and !$in_q || $buf[$p] eq $in_q
$state $p != 0 $state == 1 $buf[$p - 1] ne "\\" not $in_q $buf[$p] eq $in_q
Truth table66%6/9
A and B and C or D and not(E) or F
A= $stateB= $p != 0C= $state == 1D= $buf[$p - 1] ne "\\"E= not $in_qF= $buf[$p] eq $in_q
ABCDEFresult
0XXXXX0
10XXXX0
1100XX0
111X000
1101000
111X1X1
111X011
11011X1
1101011
219 32 ▶ if ($in_q) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in_q) { } 16 16 32
220 16 $in_q = 0;
221 } else {
222 16 $in_q = $buf[$p];
223 }
224 }
225 45 last;
226 0 }
227 4688 ▶ case '!' {
Branch: 1 branch
BranchTrueFalseTotal
if (&Switch::case("!")) 36 4652 4688
228 # JavaScript & Other HTML scripting languages
229 36 ▶ if ($state == 1 && $buf[$p-1] eq '<') {
Branch: 1 branch
BranchTrueFalseTotal
if ($state == 1 and $buf[$p - 1] eq '<') { } 23 13 36
Condition66%2/3
$state == 1 and $buf[$p - 1] eq "<"
!ll&&!rl&&r
13023
MC/DC50%1/2
$state == 1 and $buf[$p - 1] eq "<"
$state == 1 $buf[$p - 1] eq "<"
Truth table66%2/3
A and B
A= $state == 1B= $buf[$p - 1] eq "<"
ABresult
0X0
100
111
230 23 $state = 3;
231 23 $lc = $c;
232 } else {
233 13 ▶ if ($state == 0) {
Branch: 2 branches
BranchTrueFalseTotal
if ($state == 0) { } 13 0 13
elsif ($allow and $state == 1) { } 0 0 0
234 13 push @rbuf, $c;
235 ▶ } elsif ($allow && $state == 1) {
Condition0%0/3
$allow and $state == 1
!ll&&!rl&&r
000
MC/DC0%0/2
$allow and $state == 1
$allow $state == 1
Truth table0%0/3
A and B
A= $allowB= $state == 1
ABresult
0X0
100
111
236 0 push @tbuf, $c;
237 }
238 }
239 36 last;
240 0 }
241 4652 ▶ case '-' {
Branch: 1 branch
BranchTrueFalseTotal
if (&Switch::case("-")) 100 4552 4652
242 100 ▶ if ($state == 3 && $p >= 2 && $buf[$p-1] eq '-' && $buf[$p-2] eq '!') {
Branch: 1 branch
BranchTrueFalseTotal
if ($state == 3 and $p >= 2 and $buf[$p - 1] eq '-' and $buf[$p - 2] eq '!') { } 23 77 100
Condition77%7/9
$state == 3 and $p >= 2 and $buf[$p - 1] eq "-" and $buf[$p - 2] eq "!"
!ll&&!rl&&r
77023
$state == 3 and $p >= 2 and $buf[$p - 1] eq "-"
!ll&&!rl&&r
542323
$state == 3 and $p >= 2
!ll&&!rl&&r
54046
MC/DC50%2/4
$state == 3 and $p >= 2 and $buf[$p - 1] eq "-" and $buf[$p - 2] eq "!"
$state == 3 $p >= 2 $buf[$p - 1] eq "-" $buf[$p - 2] eq "!"
Truth table60%3/5
A and B and C and D
A= $state == 3B= $p >= 2C= $buf[$p - 1] eq "-"D= $buf[$p - 2] eq "!"
ABCDresult
0XXX0
10XX0
110X0
11100
11111
243 # <!-- opening finished, now inside <!-- comment -->
244 23 $state = 4;
245 } else {
246 77 next;
247 }
248 23 last;
249 77 }
250 4629 ▶ case '?' {
Branch: 1 branch
BranchTrueFalseTotal
if (&Switch::case("?")) 118 4511 4629
251 118 ▶ if ($state == 1 && $buf[$p-1] eq '<') {
Branch: 1 branch
BranchTrueFalseTotal
if ($state == 1 and $buf[$p - 1] eq "<") 53 65 118
Condition100%3/3
$state == 1 and $buf[$p - 1] eq "<"
!ll&&!rl&&r
57853
MC/DC100%2/2
$state == 1 and $buf[$p - 1] eq "<"
$state == 1 $buf[$p - 1] eq "<"
Truth table100%3/3
A and B
A= $state == 1B= $buf[$p - 1] eq "<"
ABresult
0X0
100
111
252 # opened <? PHP tag
253 53 $br=0;
254 53 $state=2;
255 53 last;
256 }
257 65 }
258 4576 ▶ case m/E|e/ {
Branch: 1 branch
BranchTrueFalseTotal
if (&Switch::case(qr/E|e/)) 297 4279 4576
259 # !DOCTYPE exception
260 297 ▶ if ($state==3 && $p > 6
Branch: 1 branch
BranchTrueFalseTotal
if ($state == 3 and $p > 6 and lc $buf[$p - 1] eq "p" and lc $buf[$p - 2] eq "y" and lc $buf[$p - 3] eq "t" and lc $buf[$p - 4] eq "c" and lc $buf[$p - 5] eq "o" and lc $buf[$p - 6] eq "d") 0 297 297
Condition33%7/21
$state == 3 and $p > 6 and lc $buf[$p - 1] eq "p" and lc $buf[$p - 2] eq "y" and lc $buf[$p - 3] eq "t" and lc $buf[$p - 4] eq "c" and lc $buf[$p - 5] eq "o" and lc $buf[$p - 6] eq "d"
!ll&&!rl&&r
29700
$state == 3 and $p > 6 and lc $buf[$p - 1] eq "p" and lc $buf[$p - 2] eq "y" and lc $buf[$p - 3] eq "t" and lc $buf[$p - 4] eq "c" and lc $buf[$p - 5] eq "o"
!ll&&!rl&&r
29700
$state == 3 and $p > 6 and lc $buf[$p - 1] eq "p" and lc $buf[$p - 2] eq "y" and lc $buf[$p - 3] eq "t" and lc $buf[$p - 4] eq "c"
!ll&&!rl&&r
29700
$state == 3 and $p > 6 and lc $buf[$p - 1] eq "p" and lc $buf[$p - 2] eq "y" and lc $buf[$p - 3] eq "t"
!ll&&!rl&&r
29700
$state == 3 and $p > 6 and lc $buf[$p - 1] eq "p" and lc $buf[$p - 2] eq "y"
!ll&&!rl&&r
29700
$state == 3 and $p > 6 and lc $buf[$p - 1] eq "p"
!ll&&!rl&&r
29700
$state == 3 and $p > 6
!ll&&!rl&&r
29700
MC/DC0%0/8
$state == 3 and $p > 6 and lc $buf[$p - 1] eq "p" and lc $buf[$p - 2] eq "y" and lc $buf[$p - 3] eq "t" and lc $buf[$p - 4] eq "c" and lc $buf[$p - 5] eq "o" and lc $buf[$p - 6] eq "d"
$state == 3 $p > 6 lc $buf[$p - 1] eq "p" lc $buf[$p - 2] eq "y" lc $buf[$p - 3] eq "t" lc $buf[$p - 4] eq "c" lc $buf[$p - 5] eq "o" lc $buf[$p - 6] eq "d"
Truth table11%1/9
A and B and C and D and E and F and G and H
A= $state == 3B= $p > 6C= lc $buf[$p - 1] eq "p"D= lc $buf[$p - 2] eq "y"E= lc $buf[$p - 3] eq "t"F= lc $buf[$p - 4] eq "c"G= lc $buf[$p - 5] eq "o"H= lc $buf[$p - 6] eq "d"
ABCDEFGHresult
0XXXXXXX0
10XXXXXX0
110XXXXX0
1110XXXX0
11110XXX0
111110XX0
1111110X0
111111100
111111111
261 && lc($buf[$p-1]) eq 'p'
262 && lc($buf[$p-2]) eq 'y'
263 && lc($buf[$p-3]) eq 't'
264 && lc($buf[$p-4]) eq 'c'
265 && lc($buf[$p-5]) eq 'o'
266 && lc($buf[$p-6]) eq 'd') {
267 # we're not in a <!-- (state=3) but in a HTML tag
268 0 $state = 1;
269 0 last;
270 }
271 # fall-through
272 0 }
273 4576 ▶ case m/L|l/ {
Branch: 1 branch
BranchTrueFalseTotal
if (&Switch::case(qr/L|l/)) 451 4125 4576
274 451 ▶ if ($state == 2 && $p > 2 && lc(join "", ($buf[$p-2], $buf[$p-1])) eq "xm") {
Branch: 1 branch
BranchTrueFalseTotal
if ($state == 2 and $p > 2 and lc join("", ($buf[$p - 2], $buf[$p - 1])) eq "xm") 0 451 451
Condition66%4/6
$state == 2 and $p > 2 and lc join("", ($buf[$p - 2], $buf[$p - 1])) eq "xm"
!ll&&!rl&&r
3441070
$state == 2 and $p > 2
!ll&&!rl&&r
3440107
MC/DC0%0/3
$state == 2 and $p > 2 and lc join("", ($buf[$p - 2], $buf[$p - 1])) eq "xm"
$state == 2 $p > 2 lc join("", ($buf[$p - 2], $buf[$p - 1])) eq "xm"
Truth table50%2/4
A and B and C
A= $state == 2B= $p > 2C= lc join("", ($buf[$p - 2], $buf[$p - 1])) eq "xm"
ABCresult
0XX0
10X0
1100
1111
275 # we're not in a <? (state=2, PHP) but in a <?xml tag (state=1, HTML)
276 0 $state = 1;
277 0 last;
278 }
279 # fall-through
280 0 }
281 4576 ▶ case m/.*/ {
Branch: 1 branch
BranchTrueFalseTotal
if (&Switch::case(qr/.*/)) 4576 0 4576
282 4576 ▶ if ($state == 0) {
Branch: 2 branches
BranchTrueFalseTotal
if ($state == 0) { } 2115 2461 4576
elsif ($allow and $state == 1) { } 958 2158 3116
283 2115 push @rbuf, $c;
284 ▶ } elsif ($allow && $state == 1) {
Condition100%3/3
$allow and $state == 1
!ll&&!rl&&r
655848958
MC/DC100%2/2
$allow and $state == 1
$allow $state == 1
Truth table100%3/3
A and B
A= $allowB= $state == 1
ABresult
0X0
100
111
285 958 push @tbuf, $c;
286 }
287 4576 last;
288 0 }
289 0 }
290 5620 $p++;
291 5620 $c = $buf[$p];
292 5620 $i++;
293 }
294  
295 134 return join "", @rbuf;
296 }
297  
298 15 1;
299  
300 __END__
↑ Summary