← Index
NYTProf Performance Profile   « line view »
For /usr/local/libexec/sympa/task_manager-debug.pl
  Run on Tue Jun 1 22:32:51 2021
Reported on Tue Jun 1 22:35:14 2021

Filename/usr/local/lib/perl5/site_perl/HTML/StripScripts/Parser.pm
StatementsExecuted 0 statements in 0s
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
0000s0sHTML::StripScripts::Parser::::BEGIN@2HTML::StripScripts::Parser::BEGIN@2
0000s0sHTML::StripScripts::Parser::::BEGIN@4HTML::StripScripts::Parser::BEGIN@4
0000s0sHTML::StripScripts::Parser::::BEGIN@68HTML::StripScripts::Parser::BEGIN@68
0000s0sHTML::StripScripts::Parser::::BEGIN@69HTML::StripScripts::Parser::BEGIN@69
0000s0sHTML::StripScripts::Parser::::BEGIN@70HTML::StripScripts::Parser::BEGIN@70
0000s0sHTML::StripScripts::Parser::::__ANON__HTML::StripScripts::Parser::__ANON__ (xsub)
0000s0sHTML::StripScripts::Parser::::filter_htmlHTML::StripScripts::Parser::filter_html
0000s0sHTML::StripScripts::Parser::::hss_initHTML::StripScripts::Parser::hss_init
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package HTML::StripScripts::Parser;
2use strict;
3
4use vars qw($VERSION);
5$VERSION = '1.03';
6
7=head1 NAME
8
9HTML::StripScripts::Parser - XSS filter using HTML::Parser
10
11=head1 SYNOPSIS
12
13 use HTML::StripScripts::Parser();
14
15 my $hss = HTML::StripScripts::Parser->new(
16
17 {
18 Context => 'Document', ## HTML::StripScripts configuration
19 Rules => { ... },
20 },
21
22 strict_comment => 1, ## HTML::Parser options
23 strict_names => 1,
24
25 );
26
27 $hss->parse_file("foo.html");
28
29 print $hss->filtered_document;
30
31 OR
32
33 print $hss->filter_html($html);
34
35=head1 DESCRIPTION
36
37This class provides an easy interface to C<HTML::StripScripts>, using
38C<HTML::Parser> to parse the HTML.
39
40See L<HTML::Parser> for details of how to customise how the raw HTML is parsed
41into tags, and L<HTML::StripScripts> for details of how to customise the way
42those tags are filtered.
43
44=cut
45
46=head1 CONSTRUCTORS
47
48=over
49
50=item new ( {CONFIG}, [PARSER_OPTIONS] )
51
52Creates a new C<HTML::StripScripts::Parser> object.
53
54The CONFIG parameter has the same semantics as the CONFIG
55parameter to the C<HTML::StripScripts> constructor.
56
57Any PARSER_OPTIONS supplied will be passed on to the L<HTML::Parser>
58init method, allowing you to influence the way the input is parsed.
59
60You cannot use PARSER_OPTIONS to set the C<HTML::Parser> event handlers
61(see L<HTML::Parser/Events>) since C<HTML::StripScripts::Parser>
62uses all of the event hooks itself.
63However, you can use C<Rules> (see L<HTML::StripScripts/Rules>) to customise
64the handling of all tags and attributes.
65
66=cut
67
68use HTML::StripScripts;
69use HTML::Parser;
70use base qw(HTML::StripScripts HTML::Parser);
71
72sub hss_init {
73 my ( $self, $cfg, @parser_options ) = @_;
74
75 $self->init(
76 @parser_options,
77
78 api_version => 3,
79 start_document_h => [ 'input_start_document', 'self' ],
80 start_h => [ 'input_start', 'self,text' ],
81 end_h => [ 'input_end', 'self,text' ],
82 text_h => [ 'input_text', 'self,text' ],
83 default_h => [ 'input_text', 'self,text' ],
84 declaration_h => [ 'input_declaration', 'self,text' ],
85 comment_h => [ 'input_comment', 'self,text' ],
86 process_h => [ 'input_process', 'self,text' ],
87 end_document_h => [ 'input_end_document', 'self' ],
88
89 # workaround for http://rt.cpan.org/NoAuth/Bug.html?id=3954
90 ( $HTML::Parser::VERSION =~ /^3\.(29|30|31)$/
91 ? ( strict_comment => 1 )
92 : ()
93 ),
94 );
95
96 $self->SUPER::hss_init($cfg);
97}
98
99=back
100
101=head1 METHODS
102
103See L<HTML::Parser> for input methods, L<HTML::StripScripts> for output
104methods.
105
106=head2 C<filter_html()>
107
108C<filter_html()> is a convenience method for filtering HTML already loaded
109into a scalar variable. It combines calls to C<HTML::Parser::parse()>,
110C<HTML::Parser::eof()> and C<HTML::StripScripts::filtered_document()>.
111
112 $filtered_html = $hss->filter_html($html);
113
114
115=cut
116
117#===================================
118sub filter_html {
119#===================================
120 my ( $self, $html ) = @_;
121 $self->parse($html);
122 $self->eof;
123 return $self->filtered_document;
124}
125
126=head1 SUBCLASSING
127
128The C<HTML::StripScripts::Parser> class is subclassable. Filter objects
129are plain hashes. The hss_init() method takes the same arguments as
130new(), and calls the initialization methods of both C<HTML::StripScripts>
131and C<HTML::Parser>.
132
133See L<HTML::StripScripts/"SUBCLASSING"> and L<HTML::Parser/"SUBCLASSING">.
134
135=head1 SEE ALSO
136
137L<HTML::StripScripts>, L<HTML::Parser>, L<HTML::StripScripts::LibXML>
138
139=head1 BUGS
140
141None reported.
142
143Please report any bugs or feature requests to
144bug-html-stripscripts-parser@rt.cpan.org, or through the web interface at
145L<http://rt.cpan.org>.
146
147
148=head1 AUTHOR
149
150Original author Nick Cleaton E<lt>nick@cleaton.netE<gt>
151
152New code added and module maintained by Clinton Gormley
153E<lt>clint@traveljury.comE<gt>
154
155=head1 COPYRIGHT
156
157Copyright (C) 2003 Nick Cleaton. All Rights Reserved.
158
159Copyright (C) 2007 Clinton Gormley. All Rights Reserved.
160
161=head1 LICENSE
162
163This module is free software; you can redistribute it and/or modify it
164under the same terms as Perl itself.
165
166=cut
167
1681;
169