| 1 | package HTML::BBCode; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | HTML::BBCode - Perl extension for converting BBcode to HTML. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | use HTML::BBCode; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | my $bbc = HTML::BBCode->new( \%options ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | my $html = $bbc->parse($bbcode); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | # Input | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | print $bbc->{bbcode}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | # Output | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | print $bbc->{html}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | C<HTML::BBCode> converts BBCode -as used on the phpBB bulletin | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | boards- to its HTML equivalent. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | Please note that, although this was the first BBCode module, it's by | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | far not the best nor fastest. It's also not heavilly maintained, so | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | you might want to look at L<BBCode::Parser> and L<Parse::BBCode>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | =head2 METHODS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | The following methods can be used | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | =head3 new | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | my $bbc = HTML::BBCode->new({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | allowed_tags => [ @bbcode_tags ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | stripscripts => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | linebreaks => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | C<new> creates a new C<HTML::BBCode> object using the configuration | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | passed to it. The object's default configuration allows all BBCode to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | be converted to the default HTML. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | =head4 options | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | =over 5 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | =item allowed_tags | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | Defaults to all currently know C<BBCode tags>, being: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | b, u, i, color, size, quote, code, list, url, email, img. With this | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | option, you can specify what BBCode tags you would like to convert. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | =item stripscripts | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | Enabled by default, this option will remove all the XSS trickery (and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | thus is probably best not to turn it off). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | =item no_html | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | This option has been removed since version 2.0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | =item no_jslink | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | This option has been removed since version 2.0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | =item linebreaks | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | Disabled by default. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | When true, will substitute linebreaks into HTML ('<br />') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | =head3 parse | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | my $html = $bbc->parse($bbcode); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | Parses text supplied as a single scalar string and returns the HTML as | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | a single scalar string. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | =head1 CAVEAT: API CHANGES | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | Please do note that the C<html_tags>, C<no_html>, C<no_jslink> options in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | the new method have been removed since version 2.0 due to the XSS protection | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | (provided by L<HTML::StripScripts::Parser>). This will most likely | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | break your current scripts (if you used the C<html_tags> option). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | =item * L<http://www.phpbb.com/phpBB/faq.php?mode=bbcode> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | =item * L<http://menno.b10m.net/perl/> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | =item * L<HTML::StripScripts::Parser>, L<HTML::BBReverse>, L<BBCode::Parser> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | =head1 BUGS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | C<Bugs? Impossible!>. Please report bugs to L<http://rt.cpan.org/Ticket/Create.html?Queue=HTML-BBCode>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | Menno Blom, E<lt>blom@cpan.orgE<gt> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | Copyright (C) 2004-2009 by Menno Blom | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | This library is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | it under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | #------------------------------------------------------------------------------# | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 17 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 17 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 17 | ▶ | use HTML::BBCode::StripScripts; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 17 | our $VERSION = '2.07'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 17 | our @bbcode_tags = qw(code quote b u i color size list url email img); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 24 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 24 | my ($class, $args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 24 | ▶ | $args ||= {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$args ||= {}
MC/DC100%1/1
$args ||= {}
$args
Truth table100%2/2
A
A= $args
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 24 | ▶ | $class->_croak("Options must be a hash reference") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | if ref($args) ne 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 24 | my $self = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 24 | bless $self, $class; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 24 | ▶ | $self->_init($args) or return undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 24 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 24 | ▶ | sub _init { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_init: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 24 | my ($self, $args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 24 | my %html_tags = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | code => '<div class="bbcode_code_header">Code:</div>'. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | '<div class="bbcode_code_body">%s</div>', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | quote => '<div class="bbcode_quote_header">%s</div>'. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | '<div class="bbcode_quote_body">%s</div>', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | b => '<span style="font-weight:bold">%s</span>', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | u => '<span style="text-decoration:underline;">%s</span>', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | i => '<span style="font-style:italic">%s</span>', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | color => '<span style="color:%s">%s</span>', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | size => '<span style="font-size:%spx">%s</span>', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | url => '<a href="%s">%s</a>', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | email => '<a href="mailto:%s">%s</a>', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | img => '<img src="%s" alt="" />', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | ul => '<ul>%s</ul>', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | ol_number => '<ol>%s</ol>', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | ol_alpha => '<ol style="list-style-type:lower-alpha;">%s</ol>', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | my %options = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | allowed_tags=> \@bbcode_tags, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | html_tags => \%html_tags, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | stripscripts => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | linebreaks => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 24 | %{ $args }, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 24 | $self->{options} = \%options; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 24 | $self->{'hss'} = HTML::BBCode::StripScripts->new({ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | Context => 'Flow', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | AllowSrc => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | AllowMailto => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | AllowHref => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | AllowRelURL => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | EscapeFiltered => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | BanAllBut => [qr/a div img li ol span ul/], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | Rules => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | br => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | img => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | required => ['src'], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 'src' => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 'alt' => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | '*' => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | a => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | required => ['href'], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 'href' => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | '*' => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | img => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 'src' => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 'alt' => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | '*' => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | div => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | class => qr{^bbcode_}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | '*' => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | span => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | style => \&_filter_style, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | '*' => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | ol => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | style => qr/^list-style-type:lower-alpha$/, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | '*' => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | ul => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | li => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 24 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | # Parse the input! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 70 | ▶ | sub parse { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse: called CC=13 SCAR=25.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 70 | my ($self, $bbcode) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 70 | ▶ | return if(!defined $bbcode); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 69 | $self->{_stack} = []; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 69 | $self->{_in_code_block} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 69 | $self->{_skip_nest} = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 69 | $self->{_nest_count} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 69 | $self->{_nest_count_stack} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 69 | $self->{_dont_nest} = ['code', 'url', 'email', 'img']; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 69 | $self->{bbcode} = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 69 | $self->{html} = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 69 | $self->{bbcode} = $bbcode; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 69 | my $input = $bbcode; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | main: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 69 | while(1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | # End tag | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 374 | ▶ | if($input =~ /^(\[\/[^\]]+\])/s) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 84 | my $end = lc $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 84 | ▶ | if(($self->{_skip_nest} ne '' && $end ne "[/$self->{_skip_nest}]") || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition77%7/9
$self->{"_skip_nest"} ne "" and $end ne qq[[/$self->{"_skip_nest"}]] or $self->{"_in_code_block"} and $end ne "[/code]"
$self->{"_skip_nest"} ne "" and $end ne qq[[/$self->{"_skip_nest"}]]
$self->{"_in_code_block"} and $end ne "[/code]"
MC/DC50%2/4
$self->{"_skip_nest"} ne "" and $end ne qq[[/$self->{"_skip_nest"}]] or $self->{"_in_code_block"} and $end ne "[/code]"
$self->{"_skip_nest"} ne ""
$end ne qq[[/$self->{"_skip_nest"}]]
$self->{"_in_code_block"}
$end ne "[/code]"
Truth table57%4/7
A and B or C and D
A= $self->{"_skip_nest"} ne ""B= $end ne qq[[/$self->{"_skip_nest"}]]C= $self->{"_in_code_block"}D= $end ne "[/code]"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | ($self->{_in_code_block} && $end ne "[/code]")) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 1 | _content($self, $end); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 83 | _end_tag($self, $end); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 84 | $input = $'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | # Opening tag | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | elsif($input =~ /^(\[[^\]]+\])/s ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 100 | ▶ | if($self->{_in_code_block}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 1 | _content($self, $1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 99 | _open_tag($self, $1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 100 | $input = $'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | # None BBCode content till next tag | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | elsif($input =~ /^([^\[]+)/s) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 118 | _content($self, $1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 118 | $input = $'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | # BUG #14138 unmatched bracket, content till end of input | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | elsif($input =~ /^(.+)$/s) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 3 | _content($self, $1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 3 | $input = $'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | # Now what? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 69 | ▶ | last main if(!$input); # We're at the end now, stop parsing! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 69 | $self->{html} = join('', @{$self->{_stack}}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 69 | ▶ | return $self->{options}->{stripscripts} ? $self->_stripscripts() : $self->{html}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 99 | ▶ | sub _open_tag { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_open_tag: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 99 | my ($self, $open) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 99 | my ($tag, $rest) = $open =~ m/\[([^=\]]+)(.*)?\]/s; # Don't do this! ARGH! | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 99 | $tag = lc $tag; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 99 | ▶ | if(_dont_nest($self, $tag) && $tag eq 'img') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
_dont_nest($self, $tag) and $tag eq "img"
MC/DC100%2/2
_dont_nest($self, $tag) and $tag eq "img"
_dont_nest($self, $tag)
$tag eq "img"
Truth table100%3/3
A and B
A= _dont_nest($self, $tag)B= $tag eq "img"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 9 | $self->{_skip_nest} = $tag; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 99 | ▶ | if($self->{_skip_nest} eq $tag) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 9 | $self->{_nest_count}++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 9 | $self->{_nest_count_stack}++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 99 | ▶ | $self->{_in_code_block}++ if($tag eq 'code'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 99 | push @{$self->{_stack}}, '['.$tag.$rest.']'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 123 | ▶ | sub _content { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_content: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 123 | my ($self, $content) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 123 | $content =~ s|\r*||gs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | $content =~ s|\n|<br />\n|gs if($self->{options}->{linebreaks} && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 123 | ▶ | $self->{_in_code_block} == 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->{"options"}{"linebreaks"} and $self->{"_in_code_block"} == 0
MC/DC100%2/2
$self->{"options"}{"linebreaks"} and $self->{"_in_code_block"} == 0
$self->{"options"}{"linebreaks"}
$self->{"_in_code_block"} == 0
Truth table100%3/3
A and B
A= $self->{"options"}{"linebreaks"}B= $self->{"_in_code_block"} == 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 123 | push @{$self->{_stack}}, $content; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 83 | ▶ | sub _end_tag { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_end_tag: called CC=16 SCAR=28.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 83 | my ($self, $end) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 83 | my ($tag, $arg); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 83 | my @buf = ( $end ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 83 | ▶ | if("[/$self->{_skip_nest}]" eq $end && $self->{_nest_count} > 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
qq[[/$self->{"_skip_nest"}]] eq $end and $self->{"_nest_count"} > 1
MC/DC0%0/2
qq[[/$self->{"_skip_nest"}]] eq $end and $self->{"_nest_count"} > 1
qq[[/$self->{"_skip_nest"}]] eq $end
$self->{"_nest_count"} > 1
Truth table66%2/3
A and B
A= qq[[/$self->{"_skip_nest"}]] eq $endB= $self->{"_nest_count"} > 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 0 | push @{$self->{_stack}}, $end; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 0 | $self->{_nest_count}--; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 83 | ▶ | $self->{_in_code_block} = 0 if($end eq '[/code]'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | # Loop through the stack | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 83 | while(1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 204 | my $item = pop(@{$self->{_stack}}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 204 | push @buf, $item; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 204 | ▶ | if(!defined $item) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 2 | ▶ | map { push @{$self->{_stack}}, $_ if($_) } reverse @buf; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 2 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 202 | ▶ | if("[$self->{_skip_nest}]" eq "$item") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 5 | $self->{_nest_count_stack}--; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 5 | ▶ | next if($self->{_nest_count_stack} > 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | $self->{_nest_count}-- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 202 | ▶ | if("[/$self->{_skip_nest}]" eq $end && $self->{_nest_count} > 0) ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
qq[[/$self->{"_skip_nest"}]] eq $end and $self->{"_nest_count"} > 0
MC/DC100%2/2
qq[[/$self->{"_skip_nest"}]] eq $end and $self->{"_nest_count"} > 0
qq[[/$self->{"_skip_nest"}]] eq $end
$self->{"_nest_count"} > 0
Truth table100%3/3
A and B
A= qq[[/$self->{"_skip_nest"}]] eq $endB= $self->{"_nest_count"} > 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 202 | ▶ | if($item =~ /\[([^=\]]+).*\]/s) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 101 | $tag = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 101 | ▶ | if ($tag && $end eq "[/$tag]") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$tag and $end eq "[/$tag]"
MC/DC50%1/2
$tag and $end eq "[/$tag]"
$tag
$end eq "[/$tag]"
Truth table66%2/3
A and B
A= $tagB= $end eq "[/$tag]"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 81 | ▶ | push @{$self->{_stack}}, (_is_allowed($self, $tag)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | ? _do_BB($self, @buf) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | : reverse @buf; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | # Clear the _skip_nest? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | $self->{_skip_nest} = '' if(defined $self->{_skip_nest} && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 81 | ▶ | $tag eq $self->{_skip_nest}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $self->{"_skip_nest"} and $tag eq $self->{"_skip_nest"}
MC/DC50%1/2
defined $self->{"_skip_nest"} and $tag eq $self->{"_skip_nest"}
defined $self->{"_skip_nest"}
$tag eq $self->{"_skip_nest"}
Truth table66%2/3
A and B
A= defined $self->{"_skip_nest"}B= $tag eq $self->{"_skip_nest"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 81 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 83 | $self->{_nest_count_stack} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 75 | ▶ | sub _do_BB { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_do_BB: called CC=10 SCAR=23.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 75 | my ($self, @buf) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 75 | my ($tag, $attr); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 75 | my $html; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | # Get the opening tag | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 75 | my $open = pop(@buf); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | # We prefer to read in non-reverse way | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 75 | @buf = reverse @buf; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | # Closing tag is kinda useless, pop it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 75 | pop(@buf); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | # Rest should be content; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 75 | my $content = join(' ', @buf); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | # What are we dealing with anyway? Any attributes maybe? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 75 | ▶ | if($open =~ /\[([^=\]]+)=?([^\]]+)?]/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 75 | $tag = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 75 | $attr = $2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | # Kludgy way to handle specific BBCodes ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 75 | ▶ | if($tag eq 'quote') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | $html = sprintf($self->{options}->{html_tags}->{quote}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 8 | ▶ | ($attr) ? "$attr wrote:" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | : "Quote:", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | $content | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | } elsif($tag eq 'code') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 3 | $html = sprintf($self->{options}->{html_tags}->{code}, _code($content)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | } elsif($tag eq 'list') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 8 | $html = _list($self, $attr, $content); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | ▶ | } elsif(($tag eq 'email' || $tag eq 'url') && !$attr) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%6/6
$tag eq "email" || $tag eq "url" and not $attr
$tag eq "email" or $tag eq "url"
MC/DC100%3/3
$tag eq "email" || $tag eq "url" and not $attr
$tag eq "email"
$tag eq "url"
not $attr
Truth table80%4/5
A or B and not(C)
A= $tag eq "email"B= $tag eq "url"C= not $attr
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 4 | $html = sprintf($self->{options}->{html_tags}->{$tag}, $content,$content); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | } elsif ($attr) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 24 | $html = sprintf($self->{options}->{html_tags}->{$tag}, $attr, $content); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 28 | $html = sprintf($self->{options}->{html_tags}->{$tag}, $content); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | # Return ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 75 | return $html; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 81 | ▶ | sub _is_allowed { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_allowed: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 81 | my ($self, $check) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | map { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 447 | ▶ | return 1 if ($_ eq $check); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 81 | } @{$self->{options}->{allowed_tags}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 6 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 99 | ▶ | sub _dont_nest { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_dont_nest: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 99 | my ($self, $check) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | map { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 345 | ▶ | return 1 if($_ eq $check); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 99 | } @{$self->{_dont_nest}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | 65 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 3 | ▶ | sub _code { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_code: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 3 | my $code = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 3 | $code =~ s|^\s+?[\n\r]+?||; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 3 | $code =~ s|<|\<|g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 3 | $code =~ s|>|\>|g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 3 | $code =~ s|\[|\[|g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 3 | $code =~ s|\]|\]|g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | 3 | $code =~ s| |\ |g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 3 | $code =~ s|\n|<br />|g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 3 | return $code; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 8 | ▶ | sub _list { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_list: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 8 | my ($self, $attr, $content) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | 8 | $content =~ s|^<br />[\s\r\n]*|\n|s; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 8 | $content =~ s|\[\*\]([^\[]+)|_list_removelastbr($1)|egs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | 8 | $content =~ s|<br />$|\n|s; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | 8 | ▶ | if($attr) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | 4 | ▶ | return sprintf($self->{options}->{html_tags}->{ol_number}, $content) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | if($attr =~ /^\d/); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | 2 | ▶ | return sprintf($self->{options}->{html_tags}->{ol_alpha}, $content) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | if($attr =~ /^\D/); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 4 | return sprintf($self->{options}->{html_tags}->{ul}, $content); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | 18 | ▶ | sub _list_removelastbr { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_list_removelastbr: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | 18 | my $content = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | 18 | $content =~ s|<br />[\s\r\n]*$||; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | 18 | $content =~ s|^\s*||; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | 18 | $content =~ s|\s*$||; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | 18 | return "<li>$content</li>\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | 67 | ▶ | sub _stripscripts { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_stripscripts: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | 67 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | 67 | $self->{'html'} = $self->{'hss'}->filter_html($self->{'html'}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 67 | return $self->{'html'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | 29 | ▶ | sub _filter_style { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_filter_style: called CC=10 SCAR=23.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | 29 | my ($filter, $tag, $attr_name, $attr_val) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | 29 | ▶ | if ($attr_val eq 'font-weight:bold' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition88%8/9
$attr_val eq "font-weight:bold" or $attr_val eq "text-decoration:underline" or $attr_val eq "font-style:italic" or $attr_val eq "list-style-type"
$attr_val eq "font-weight:bold" or $attr_val eq "text-decoration:underline" or $attr_val eq "font-style:italic"
$attr_val eq "font-weight:bold" or $attr_val eq "text-decoration:underline"
MC/DC75%3/4
$attr_val eq "font-weight:bold" or $attr_val eq "text-decoration:underline" or $attr_val eq "font-style:italic" or $attr_val eq "list-style-type"
$attr_val eq "font-weight:bold"
$attr_val eq "text-decoration:underline"
$attr_val eq "font-style:italic"
$attr_val eq "list-style-type"
Truth table80%4/5
A or B or C or D
A= $attr_val eq "font-weight:bold"B= $attr_val eq "text-decoration:underline"C= $attr_val eq "font-style:italic"D= $attr_val eq "list-style-type"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | or $attr_val eq 'text-decoration:underline' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | or $attr_val eq 'font-style:italic' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | or $attr_val eq 'list-style-type') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | 22 | return $attr_val; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | 7 | ▶ | if ( my ($color) = $attr_val =~ /^color:(.*)/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | 4 | my @html_color = qw/ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | black gray maroon red green lime olive yellow | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | navy blue purple fuchsia teal aqua silver white | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | /; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 4 | ▶ | return $attr_val if $color =~ /^#[a-fA-F\d]{6}$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | 4 | ▶ | return $attr_val if $color =~ /^#[a-fA-F\d]{3}$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | 4 | ▶ | return $attr_val if grep { $color eq $_ } @html_color; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | 3 | ▶ | if ( $attr_val =~ /font-size:\d+px/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | 2 | return $attr_val; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | 1 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | 0 | ▶ | sub _croak { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_croak: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | 0 | my ($class, @error) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | 0 | require Carp; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | 0 | Carp::croak(@error); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | 17 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||